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: 
Nethram
Visitor

Roku scene graph - How to send data from roSGnode to parent.

Hi,
In my app I have a trial button,a signin button and a signup button in scene that created from "main.brs" .When trial button clicked , it will create roSGnode as follows.

sub init
m.trial= m.top.findNode("trial")
m.trial.ObserveField("buttonSelected", "startsignup")

end sub

function startsignup()

m.firstpage.visible= false
m.subscription = createObject("roSGNode","Subscription")
m.top.appendChild(m.subscription)
m.subscription.setFocus(true)

end function

The created roSGnode has a button group with two buttons. 

Subscription.xml


<component name = "Subscription" extends = "Group" initialFocus="fullcontent">
<children >

<Group>
<ButtonGroup id="submit" 
layoutDirection = "horiz"
translation = "[ 500,600]"
/>

</Group>

</children>

</component>


Subscription.brs

sub init()

m.buttongroup = m.top.findNode("submit")
m.buttongroup.buttons = [ "DECLINE", "ACCEPT" ]
m.buttongroup.ObserveField("buttonSelected","submit")

end sub


function submit()
if  m.buttongroup.buttonSelected = 1 then
m.accepted = createObject("roSGNode","Accepted")
m.top.appendChild(m.accepted)
m.accepted.setFocus(true)
else
?"Back to home scene"
end if
end function


I want to send a notification from the child to home scene and  remove the child when user clicks the "cancel" button.
please help me to solve this problem.
0 Kudos
2 REPLIES 2
joetesta
Roku Guru

Re: Roku scene graph - How to send data from roSGnode to parent.

add an interface field to your child (trial) node.
<interface>
    <field id="watchThis" type="boolean" value="false"/>
</interface>



observe the interface field from the parent node
m.trial.observeField("watchThis", "doSomething")

sub doSomething()
    'Remove child node'
   m.top.removeChild(m.trial)
end sub


when your button is clicked in the child, set the field to true in the child component,
function submit()
    m.top.watchThis = true
end function
aspiring
0 Kudos
Nethram
Visitor

Re: Roku scene graph - How to send data from roSGnode to parent.

It worked ! Thank you so much.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.