Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
joycewang
Level 7

onKeyEvent cannot recognize custom component

Hi, I'm new to Scene Graph xml. I meet an problem recently, that I create a custom xml component "CustomButton". It works good when I try to create it in init() function, but it cannot be created in onKeyEvent() function. Here is the sample code:


<?xml version="1.0" encoding="utf-8" ?>
<component name="CustomButton" extends="Group">
<children>
<Poster id="background" />
<Poster id="focusBox" />
<Label id="text" />
</children>
</component>



<?xml version="1.0" encoding="utf-8" ?>
<component name="channelListScreen" extends="Group">
<script type="text/brightscript">
<![CDATA[
function init() as Void
a = createObject("roSGNode", "CustomButton")
? a ' a is a roSGNode here
end function

function onKeyEvent(key as String, press as Boolean) as Boolean
a = createObject("roSGNode", "CustomButton")
? a ' a is Invalid here
end function
]]>
</script>
<children>
<Label text="Channel List Screen"/>
</children>
</component>


Anyone could help me? Thanks in advance!
0 Kudos
5 Replies
BCVatOVG
Level 7

Re: onKeyEvent cannot recognize custom component

I am running into this exact same problem. Have you found a solution or workaround?
0 Kudos
Dhir_Pratap
Level 7

Re: onKeyEvent cannot recognize custom component

I can also confirm this issue. Cannot create custom component in onKey Event
0 Kudos
joycewang
Level 7

Re: onKeyEvent cannot recognize custom component

I'm now creating custom components dynamically in code, based on basic renderable nodes.

function createCustomButton(opts as Object) as Object
customButton = {
node: Invalid

setup: function(opts as Object) as Void
m.node = createObject("roSGNode", "Group")

m.node.appendChild(createPoster().node)
m.node.appendChild(createPoster().node)
m.node.appendChild(createLabel().node)
end function
}

customButton.setup(opts as Object)
return customButton
end function


However there's a drawback, there is no onKeyEvent in each component, and I cannot use the feature of focus chain provided by Scene Graph XML. I have to create my own focus mananger to handle the key event and navigation.

Please suggest if you have better solutions.
0 Kudos
brybott
Level 7

Re: onKeyEvent cannot recognize custom component

Yes, I also can confirm this doesn't work. Another drawback to joycewang's approach is that you can't use any custom interface fields.

In addition to not working with onKeyEvent, custom components also return invalid when created within node.observeField() callback functions.

It would make me happy if Roku would indicate if this is something on their radar of things to update/fix.
0 Kudos
brybott
Level 7

Re: onKeyEvent cannot recognize custom component

My device updated to 7.1 firmware today, and this doesn't seem to be a problem anymore after preliminary testing. Smiley Very Happy
0 Kudos