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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using roUrlTransfer from within a scene

Hi Forum

I appreciate the help I've gotten so far from you. I came here with a new question. I've tried to create a roUrlTransfer from a scene I've loaded, but as expected it says it is invalid or unitialized. My main.brs is as followed:

 sub RunUserInterface()
    screen = CreateObject("roSGScreen")
    scene = screen.CreateScene("HomeScene")
    port = CreateObject("roMessagePort")
   scene.gridContent = ParseJsonContent(list)
while true
        msg = wait(0, port)
        print "--------- o --------"
        print "msg = "; msg
        print clock
    end while
    if screen <> invalid then
        screen = invalid
    end if    
end sub

Within this main.brs, I make a few calls using CreateObject("roUrlTransfer") without any problems, but when I tried to create this within my "HomeScene" it wasn't possible. After checking the forum it said that I should use interfaces in order to make the calls, but as far as I understood it can not be referenced directly (it seems roSgNode does not support objects). Global variable is not an option either. Some people create functions in order to make it happen, but I did not understand it fully ( ... ne#p533154)  Am I too far from the correct way? Can I get some guidance? 
0 Kudos
Roku Guru

Re: Using roUrlTransfer from within a scene

There are 3 kinds of contexts (sometimes referred to as "threads" because well, execution happens in different threads - which determines the limitations of the context): main, render and task. When function/code is executed in the scene graph render thread, no long-lasting calls are allowed since that thread is the one that redraws the screen tens of times per second - blocking that for e.g. waiting on network call means the screen freezing. Consequently, roUrlTransfer is banned from the render thread - which happens to be all functions/events (init()/onKeyEvent() etc) in a scene. Meaning, you have to do network calls either in the main thread or spin off a task for that.
0 Kudos

Re: Using roUrlTransfer from within a scene

Thank you for your reply EnTerr, and sorry for the late reply, I believed I had already done it. I created a Task exclusively to make the calls to the server given your explanation and have worked perfectly so far! Thank you for taking your time explaining it!

0 Kudos