I have a Sprite which is a child of a Flex object, and acts as the main “game window”. So during game-play it should get keyboard input but at other times not. When I add a keyboard listener to it, it never fires.
Do I need to stop parent objects ‘eating’ the events somehow, or something similar? I get the same thing with mouse-wheel events, but mouse-click events are fine. Sprite doesn’t seem to have the concept of focus unless I missed it.
More generally in this kind of approach, are there any suggestions on the best way? For instance some keys might still be needed to be intercepted before getting to the game-window, like ESC or F1 or something… the aim is the game-window isn’t aware of other UI.
Your sprite needs to have input focus to receive Keyboard Events.
As for best practices: If your entire application is based on keyboard input, and if you don’t have to switch contexts ( the same key means a different thing if another object is selected ) a lot, you could just add the listeners to the stage.
Otherwise, you can use stage.focus to set the focus to the desired object.