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: 
jedashford
Channel Surfer

How would I send data to a scene graph instance?

How would I send data to a scene graph instance? I just need to send a single string to the init() function. I cant really find a way to do this.

I've tried to set an interface and listener inside my "videoDetailScene", but the listener is never fired when I call the scene.setField below:

scene = screen.CreateScene("videoDetailScene")

screen.show()

scene.setField("workid", "20000")
0 Kudos
5 REPLIES 5
BCVatOVG
Visitor

Re: How would I send data to a scene graph instance?

How did you set up the workid field in the <interface> section of the videoDetailScene XML? You would need to set the onChange field to the specific function you want to call when you set the workid.

The problem you are probably seeing is that the init() function is called when you call screen.show() so if you are reading the workid in the init, you need to set it before you call screen.show()
0 Kudos
BCVatOVG
Visitor

Re: How would I send data to a scene graph instance?

pkg:/components/videoDetailScene.xml
<?xml version="1.0" encoding="utf-8" ?> 

<component name="videoDetailScene" extends="Scene" >

<interface>
<field id = "workid" type = "integer" onChange = "SetWorkid" />
</interface>

<script type="text/brightscript" uri="pkg:/components/videoDetailScene.brs" />

</component>

pkg:/components/videoDetailScene.brs

sub init()
' you should see 20000 in the debug output
print m.top.workid
end sub

'alternatively, because we set an onChange listener, whenever workid is changed it will call this function (even after the component is initialized)
sub SetWorkid()
' you should see 20000 in the debug output
print m.top.workid
end sub

pkg:/source/main.brs

sub Main(external_params as object)

scene = screen.CreateScene("videoDetailScene")

scene.setField("workid", "20000")

screen.show()

end sub
0 Kudos
jedashford
Channel Surfer

Re: How would I send data to a scene graph instance?

That was it, thank you so much for that insight. I was adding an ObserveField in the init():

m.top.ObserveField("workid", workidChange)


but it never worked. Adding the 'onChange' in the interface works like a charm. Not sure how I missed that.

<field id="workid" type="String" onChange="workidChange"/>
0 Kudos
softworkz
Visitor

Re: How would I send data to a scene graph instance?

My experience with this forum is rather frustrating. So many questions I have were already asked but most of them simply left unanswered or unsolved in single-post threads.
At least I can help in this case:
Wrong:
m.top.ObserveField("workid", workidChange)

Right:
m.top.ObserveField("workid", "workidChange")
0 Kudos
EnTerr
Roku Guru

Re: How would I send data to a scene graph instance?

"softworkz" wrote:
My experience with this forum is rather frustrating. So many questions I have were already asked but most of them simply left unanswered or unsolved in single-post threads.

If old thread, wake it up with "me too" follow-up query. 
If new, give it 1-2 weeks wait for reply and if no response, email developer at roku.com with link to the thread.
I personally try to remember posting answer even to old questions if i have found it by other means.

At least I can help in this case:

Well done, sir. Welcome to helping each other in the forum! 
0 Kudos