i have one poster if i click the ok what i write in the observerField and xml interface part alisa="" what i write
I don't understand the problem. Can you please try and better explain what you're trying to do, and then what is not working? Give code examples as well.
okk i create one it is the posterpage extends with group <poster id="poster" height="278" widht="122" uri="pkg://images/poster_uri.png"> . if it is hasFocus()=true then i press ok then
<interface>
<field id="posterSelected" type="node" alias="poster. ? ">
<interface>
in above alias ? what i write if press ok..
another .brs file is posterlogic.brs
sub init()
m.posterpage=createObject("roSGNode","posterpage")
m.posterpage.observerField("posterSelected","onPosterSelected")
end sub
function onPosterSelected()
print "posterSelected"
end function
Posters don't have an itemSelected property. I think you need to use a posterGrid with one poster.
https://developer.roku.com/docs/references/scenegraph/list-and-grid-nodes/postergrid.md
I'm still not entirely sure what your exact issue is, but I'll try to answer as best I can.
Unlike web-based apps, Roku SceneGraph nodes do not have events for when a specific element is clicked for most situations. Items in the scene can have focus, and parent items also technically have focus and are "in the focus chain".
Completely separate from that, there's a per-component `onKeyEvent` function that intercepts remote button down/up events. You have to write your own logic to determine what item has focus whenever a key event fires.
Here's a small example of an app with some simple focus management.
You can see this simple example app here on github: https://github.com/rokucommunity/sample-projects/tree/master/simple-focus
But here's the code as well:
<?xml version="1.0" encoding="utf-8"?>
<component name="MainScene" extends="Scene">
<script type="text/brightscript" uri="MainScene.brs" />
<interface>
<field id="appExit" type="bool" alwaysnotify="true" value="false" />
</interface>
<children>
<rectangle id="focusRing" color="0xFF69B4FF" width="310" height="310" translation="[95,95]" />
<Rectangle id="red" color="0xFF0000FF" width="300" height="300" translation="[100,100]" />
<Rectangle id="green" color="0x00FF00FF" width="300" height="300" translation="[500,100]" />
<Rectangle id="blue" color="0x000000FF" width="300" height="300" translation="[900,100]" />
<Rectangle id="black" color="0x0000FFFF" width="300" height="300" translation="[1300, 100]" />
</children>
</component>
sub init()
'get notified anytime the focus changes
m.focusRing = m.top.findNode("focusRing")
m.nodesToFocus = [
m.top.findNode("red"),
m.top.findNode("green"),
m.top.findNode("blue")
m.top.findNode("black")
]
m.nodesToFocus[0].setFocus(true)
m.top.observeField("focusedChild", "onFocusedChildChange")
end sub
'draw a focus ring around the focused element
sub onFocusedChildChange()
print "focus has changed"
focusedChild = m.top.focusedChild
'if we have a focusedChild and it's not the main scene (which has no ID)
if focusedChild <> invalid and focusedChild.id <> "" then
print "Currently focused element: " + focusedChild.id
m.focusRing.translation = [
focusedChild.translation[0] - 5,
focusedChild.translation[1] - 5
]
end if
end sub
'Set focus to the next sibling in the specified direction
sub focusNextSibling()
nodeToFocus = invalid
'focus the next child
for i = 0 to m.nodesToFocus.count() - 1
child = m.nodesToFocus[i]
'skip the focusRing
if child.id = "focusRing"
continue for
end if
if child.hasFocus()
nodeToFocus = m.nodesToFocus[i + 1]
exit for
end if
end for
'if we have no node to focus, then focus the first node that's not the focusRing
if nodeToFocus = invalid
nodeToFocus = m.nodesToFocus[0]
end if
nodeToFocus.setFocus(true)
end sub
function onKeyEvent(key as string, press as boolean) as boolean
'only handle key up events
if press <> true
return false
end if
'simple focus management for now, just move forwards or backwards
if key = "up" or key = "right" or key = "down" or key = "left"
focusNextSibling()
return true
end if
if key = "OK" then
print "Item was selected", m.focusedChild.id
return true
end if
return false
end function