Forum Discussion

shaharbad's avatar
shaharbad
Channel Surfer
3 years ago

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.
 

6 Replies

  • C-DP's avatar
    C-DP
    Channel Surfer

    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.   

    • shaharbad's avatar
      shaharbad
      Channel Surfer

      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.

      • philanderson777's avatar
        philanderson777
        Roku Guru

        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