Forum Discussion
RokuRobB
10 years agoStreaming Star
It would be helpful to see the original sample. I just created the sample below with no issues:
SimpleButtonScene.xml
<?xml version="1.0" encoding="utf-8" ?>
<!--********** Copyright 2016 Roku Corp. All Rights Reserved. **********-->
<component name="SimpleButtonScene" extends="Scene" >
<script type="text/brightscript" uri="pkg:/components/SimpleButtonScene.brs" />
<children>
<Group id="myGroup">
<Button id="button" text="Press Me!" translation="[100, 100]" />
<Button id="button1" text="Button 1" translation="[100, 160]" />
<Label id="myLabel" text="Test label" vertAlign="center" horizAlign="center" translation="[400, 100]" />
</Group>
</children>
</component>
SimpleButtonScene.brs
'********** Copyright 2016 Roku Corp. All Rights Reserved. **********
function init()
m.button= m.top.findNode("button")
m.button1 = m.top.findNode("button1")
m.button.ObserveField("buttonSelected", "onButtonSelected")
m.button1.ObserveField("buttonSelected", "onSubmitButtonSelected")
m.button.SetFocus(true)
m.label = m.top.FindNode("myLabel")
end function
function onButtonSelected() as void
m.label.text = "Button Pressed"
end function
function onSubmitButtonSelected() as void
m.label.text = "Button1 Pressed"
end function
function onKeyEvent(key as String, press as Boolean) as Boolean
handled = false
if press then
if (key = "down") then
if (m.button.hasFocus())
m.button1.setFocus(true)
else
m.button.setFocus(true)
end if
handled = true
else if (key = "up")
if (m.button1.hasFocus())
m.button.setFocus(true)
else
m.button1.setFocus(true)
end if
handled = true
end if
end if
return handled
end function
SimpleButtonScene.xml
<?xml version="1.0" encoding="utf-8" ?>
<!--********** Copyright 2016 Roku Corp. All Rights Reserved. **********-->
<component name="SimpleButtonScene" extends="Scene" >
<script type="text/brightscript" uri="pkg:/components/SimpleButtonScene.brs" />
<children>
<Group id="myGroup">
<Button id="button" text="Press Me!" translation="[100, 100]" />
<Button id="button1" text="Button 1" translation="[100, 160]" />
<Label id="myLabel" text="Test label" vertAlign="center" horizAlign="center" translation="[400, 100]" />
</Group>
</children>
</component>
SimpleButtonScene.brs
'********** Copyright 2016 Roku Corp. All Rights Reserved. **********
function init()
m.button= m.top.findNode("button")
m.button1 = m.top.findNode("button1")
m.button.ObserveField("buttonSelected", "onButtonSelected")
m.button1.ObserveField("buttonSelected", "onSubmitButtonSelected")
m.button.SetFocus(true)
m.label = m.top.FindNode("myLabel")
end function
function onButtonSelected() as void
m.label.text = "Button Pressed"
end function
function onSubmitButtonSelected() as void
m.label.text = "Button1 Pressed"
end function
function onKeyEvent(key as String, press as Boolean) as Boolean
handled = false
if press then
if (key = "down") then
if (m.button.hasFocus())
m.button1.setFocus(true)
else
m.button.setFocus(true)
end if
handled = true
else if (key = "up")
if (m.button1.hasFocus())
m.button.setFocus(true)
else
m.button1.setFocus(true)
end if
handled = true
end if
end if
return handled
end function