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"
 
- Gordon

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Danko Kozar
Sent: Wednesday, March 07, 2007 3:20 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] UIComponent: keyUpHandler - what's it for anyway?



The livedocs suggest that every UIComponent has automatically set 
event listeners for keyUp (adn keyDown) events: 
http://livedocs.adobe.com/flex/2/langref/mx/core/UIComponent.html#key
<http://livedocs.adobe.com/flex/2/langref/mx/core/UIComponent.html#key> 
UpHandler()

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.

Here's my code:

override protected function keyUpHandler(event:KeyboardEvent):void {
super.keyUpHandler(event);
if (event.keyCode == Keyboard.DELETE){
mx.controls.Alert.show("Key DELETE clicked.");
}
}

(ps. I prefer not to register key listeners by myself 
(using "addEventListener"), rather use this default behaviour if 
possible)



 

Reply via email to