Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Helaman
Channel Surfer

Code Won't Navigate Down from First Option in Menu

Hi guys! First post. Anyways, I've got a real head-scratcher with this one. I am making a basic Roku app at the moment with a menu, and I have a few options on the screen that are position on top of each other - a `TextEditBox` and a couple `Button` objects. When you press "up" or "down" you can swap between these options. This works... except for when I press "down" from the first option. I have a basic debugger that will show me if certain parts of the code execute, and it shows that navigation works fine EXCEPT for when I press "down" while the focus is on the first option in the menu. The conditional statement doesn't even get executed while the focus is on the first element, but I can tell that the TV is getting the signal from the remote (little light flashes on the TV). This has been driving me kind of nuts haha

Anyways, here is the code of the `if` statements that handle the "up" and "down" `onKeyEvent`s (it's super explicitly typed, but this is so that I don't have to worry about issues lying elsewhere):
```

if key = "down"
    m.debugger.text = "down"
    if m.selectedIndex = 0
        m.firstButton.setFocus(true)
        m.selectedIndex = 1
    else if m.selectedIndex = 1
        m.secondButton.setFocus(true)
        m.selectedIndex = 2
    else if m.selectedIndex = 2
        m.textBox.setFocus(true)
        m.selectedIndex = 0
    end if
else if key = "up"
    m.debugger.text = "up"
    if m.selectedIndex = 0
        m.firstButton.setFocus(true)
        m.selectedIndex = 2
    else if m.selectedIndex = 2
        m.secondButton.setFocus(true)
        m.selectedIndex = 1
    else if m.selectedIndex = 1
        m.textBox.setFocus(true)
        m.selectedIndex = 0
    end if
end if
```
Like I said, when the index is at 0 and the focus is on the `textBox`, the debugger I have doesn't show "down" like it should and the only thing that happens is that whatever is typed into the text box disappears, but then comes back if I navigate all the way around back to the text box. But "up" always works, and "down" works when I am on the first or second buttons (indexes 1 and 2, respectively). Thank you in advance for your help 🙂

0 Kudos
2 REPLIES 2
Helaman
Channel Surfer

Re: Code Won't Navigate Down from First Option in Menu

Ok, I figured out the problem (still don't understand the "why" though...). Putting focus on a `TextEditBox` and then trying to put the focus on a `Button` just wasn't working. I had to replace the `TextEditBox` with a `Button` and now the navigation works completely as expected. Still don't really know why this was a problem, but at least it works now.

Also, as a side note, to kind of simulate that the text box had focus I just put the button behind it and set it's `visible` property to "false". However, this did NOT work. So, for those of you with the same issue, I replaced the label I had for the text box with the button, so that the label is focusable and brings up the keyboard/pinpad when the label button is pressed.

Roku app development is somethin else...

Happy coding!

0 Kudos
speechles
Roku Guru

Re: Code Won't Navigate Down from First Option in Menu

The TextEditBox likely has its own OnKeyEvent and its returning true for that keypress and keeping it. You just look upstream from where you are into anything that extends from it. Since the keypress trickles down the very top object can return true on that keypress and swallow it. If it returns false you can also have scripts further down the chain react to that same keypress.

That is why it doesn't work as you expected to get the keypress to pass you must return false in your OnKeyEvent handler for that keypress to have it move down to the next script and so on.

Hope you understand. If you do not let us know.

Because your button label thing you mention where you simulate focus of the text edit box has me thinking you do not understand. Mainly because that is so wrong.

0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.