Managing focus in AIR for TV applications

Here’s another design consideration for AIR for TV applications. (This and other tips will be incorporated soon into Adobe online documentation).

When a user interface element has the focus in a desktop application, it is the target of user input events such as keyboard and mouse events. Furthermore, an application highlights the user interface element with the focus. Managing focus in an AIR for TV application is different from managing focus in a desktop application because:

  • Desktop applications often use the tab key to change focus to the next user interface element. Using the tab key doesn’t apply to AIR for TV applications. Remote control devices do not typically have a tab key. Therefore, managing focus with the tabEnabled property of a DisplayObject like on the desktop does not apply.
  • Desktop applications often expect the user to use the mouse to give focus to a user interface element.

Therefore, in your application, do the following:

  • Add an event listener to the Stage that listens for Keyboard events such as
    KeyboardEvent.KEY_DOWN.
  • Provide application logic to determine which user interface element to highlight to the end user. Be sure to highlight a user interface element when the application starts.
  • Based on your application logic, dispatch the Keyboard event that the Stage received to the appropriate user interface element object.

    You can also use Stage.focus or Stage.assignFocus() to assign the focus to a user interface element. You can then add an event listener to that DisplayObject so that it receives keyboard events.