For the below code, I have two questions... For this particular snippet it was part of a scene where I threw a bunch of components into the scene just to test them out... there is a button component for which I "select" when I press the down key. Originally, when I pressed any other key was setting m.button.setFocus(False).
Question 1: Why, when I set this to `false` did my focus just disappear into the scene and no additional key events could be captured?
Question 2: I 'fixed' the problem by losing focus on the button, which didn't highlight it anymore, and then returning focus to m.top. Is this the correct "pattern" to use? It feels odd to me that I would have to explicitly lose focus on something before re-gaining the parent focus I once I had.
I can paste more code, but I figured this is a pretty 'n00b' question.
Function onKeyEvent(key as String, press as Boolean) as Boolean handled = false
if press if key = "down" ? "down was pressed" m.button.setFocus(True) handled = True else m.button.setFocus(False) m.top.setFocus(True) ? "some other button was pressed" handled = True end if end if
ok.. so I read that page like 10x while hunting this problem down and I completely ignored that giant yellow cautionary message... thanks for pointing that out to me.
So a follow up question (and I apologize if I am missing this yet again in the documentation): Below is the other portion of this code... when I setFocus(True) to some other "component" in this scene can anything in this scene "take focus"? For instance, since I just have one button, up and down can always go to the button focus, but then when I want to move focus can I move it to the rectangle or to do the label (even tho it doesn't make sense to move the focus there) -- my expectation is to move the focus to some "ghost" element/component such that focus is "hidden" from the user, but then pressing `up` or `down can then be captured/set back to the button.
DISCLAIMER: This is not functional code, but rather a smattering of various Roku SDK examples/SDK docs to help me learn, so I completely understand that this is not 'best', just asking so I can understand how this works in context of what I've frankensteined together.
yeah, no need to apologize, we are all learning and the docs aren't the easiest to follow. To answer your question, "yes" any Node element can be made focusable by setting its "focusable" field to true https://sdkdocs.roku.com/display/sdkdoc/Node so in your example, add to your rectangle's XML definition:
then you can do other stuff like have the node observe it's focusedChild and when it changes, change size or color or position if node.hasFocus() = true