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

Get the information on which node triggered an event

Jump to solution

Ok, I have a very simple PosterGrid:

<PosterGrid
    id="main_menu"
    translation="[32,32]"
    basePosterSize="[640,270]"
    itemSpacing="[32,32]"
    numColumns="2"
    numRows="2">

    <ContentNode role = "content" >
        <ContentNode id="node_1" hdgridposterurl="pkg:/images/image_1.png" focusable="true"/>
        <ContentNode id="node_2" hdgridposterurl="pkg:/images/image_2.png" focusable="true"/>
        <ContentNode id="node_3" hdgridposterurl="pkg:/images/image_3.png" focusable="true"/>
        <ContentNode id="node_4" hdgridposterurl="pkg:/images/image_4.png" focusable="true"/>
    </ContentNode>
</PosterGrid>

What I want to do is process the OK key and get which node was clicked.

I read about roSGNodeEvent but I can't find any example on how to use this, documentation is very lacking. I have:

FUNCTION onKeyEvent(key as String, press as Boolean) as Boolean

    IF (press = false) THEN
         ' What do i put here? is there a way to access the roSGNodeEvent here?

         I want something that returns "node_X" depending on which Node the OK button was clicked.
    END IF

END FUNCTION

0 Kudos
1 Solution

Accepted Solutions
renojim
Community Streaming Expert

Re: Get the information on which node triggered an event

Jump to solution

In general, you don't process key presses, you set up observers on events.

Sub init()
    m.menu_grid = m.top.findNode("menu_grid")
    m.menu_grid.observeField("itemSelected","onPosterSelected")
    ...
End Sub

Sub onPosterSelected(obj as Object)
    ' m.menu_grid.itemSelected has the index number of the poster selected
    ' as does obj.GetData()
    ' do your stuff here
End Sub

 

This is a core concept of Scene Graph that you'll need to understand.

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.

View solution in original post

3 REPLIES 3
renojim
Community Streaming Expert

Re: Get the information on which node triggered an event

Jump to solution

In general, you don't process key presses, you set up observers on events.

Sub init()
    m.menu_grid = m.top.findNode("menu_grid")
    m.menu_grid.observeField("itemSelected","onPosterSelected")
    ...
End Sub

Sub onPosterSelected(obj as Object)
    ' m.menu_grid.itemSelected has the index number of the poster selected
    ' as does obj.GetData()
    ' do your stuff here
End Sub

 

This is a core concept of Scene Graph that you'll need to understand.

Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
melev
Channel Surfer

Re: Get the information on which node triggered an event

Jump to solution

Awesome! This is exactly what I needed, thanks a lot.

0 Kudos
gabak8
Streaming Star

Re: Get the information on which node triggered an event

Jump to solution

To obtain information on which node triggered an event, you would typically cutting need access to the specific system or software that handles event tracking and logging.

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.