Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
melev
Level 8

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

2 REPLIES 2
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
Level 8

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