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.

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.

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.

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

this didnt really help, any other ideas?

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 … :slightly_smiling_face:

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()

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