problem:
The livedocs suggest that every UIComponent has automatically set event listeners for keyUp (and keyDown) events. So, I expected that it’s enough to override this method to make
some action on key-click. But that isn’t the case.. Instead – nothing happens.
resolvent:
The UIComponent constructor has the logic
if (this is IFocusManagerComponent)
{
addEventListener(FocusEvent.FOCUS_IN, focusInHandler);
addEventListener(FocusEvent.FOCUS_OUT, focusOutHandler);
addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
}
In order to receive keyboard events, your component must implement IFocusManagerComponent:
“The base implementations of this interface are in the UIComponent class, but UIComponent does not implement the full IFocusManagerComponent interface since some UIComponents are not intended to receive focus. Therefore, to make a UIComponent-derived component be a valid focusable component, you simply add “implements IFocusManagerComponent” to the class definition.”
If you’re writing an MXML component, you declare that it implements an interface with the tag attribute
implements="mx.managers.IFocusManagerComponent"