Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
shaharbad
Channel Surfer

How to use a callback function inside my app?

In a channel I'm developing I have 2 functions that I call but I first need the first one to finish and then run the second one.

I tried doing this but it doesn't call the callback function:

requestNonceButton.observeField("itemSelected", "function1", function2
I also tried adding quotation marks to it.
 
Thanks a lot in advance.
 
0 Kudos
6 REPLIES 6
C-DP
Channel Surfer

Re: How to use a callback function inside my app?

You could just call function2 from function1. 

observefield does not have support for listing multiple callback functions. You would have to observe the field twice but then you are not guaranteed callback order.   

0 Kudos
shaharbad
Channel Surfer

Re: How to use a callback function inside my app?

I tried it, but In function 1 I'm accessing a url which takes some time to assign it to the variable and meanwhile the function 2 gets called which cause a problem in my particular app.

0 Kudos
philanderson777
Roku Guru

Re: How to use a callback function inside my app?

is this any help?

 

callback1 = "function1"
callback2 = "function2"

requestNonceButton.observeField("itemSelected", callback1, callback2) 

' have to set this field in the XML of the component as an interface
requestNonceButton.observeField("thisField", callback3)

function callback1(callback2 as String)
  ' do some stuff

  ' trigger second event when done
  requestNonceButton.thisField = callback2
  

  

 

0 Kudos
shaharbad
Channel Surfer

Re: How to use a callback function inside my app?

this didnt really help, any other ideas?

0 Kudos
philanderson777
Roku Guru

Re: How to use a callback function inside my app?

Hi, thanks for this.

 

I've created an invite link for you to join the Roku Developers Slack workspace

 

https://join.slack.com/t/rokudevelopers/shared_invite/zt-1vjv6k513-~4Nf8uNTDJ1SHYTvUkbpDw

 

please join and post in the #general slack channel...

 

The community there are super helpful and often you will get a clear and timely reply, I will be there also.... sorry I'm a tech lead developer so my time is really constrained ... cheers ... 🙂 

PS the solution suggested by the other person would not help - are you passing the callbacks as a parameter?  if not you can do


 

callback = "doSomeStuff"
requestNonceButton.observeField("itemSelected", callback) 


function doSomeStuff
  ' run some code 
  ' when completed
  doSomeOtherStuff()

 

0 Kudos
Vinay92
Newbie

Re: How to use a callback function inside my app?

Thanks for sharing useful information about the callback issue in app.