Flash Lite 2.x and 3.0 ActionScript Language Reference

addListener (Key.addListener method)

public static addListener(listener:Object) : Void

Registers an object to receive onKeyDown and onKeyUp notification. When a key is pressed or released, regardless of the input focus, all listening objects registered with addListener() have either their onKeyDown method or their onKeyUp method invoked. Multiple objects can listen for keyboard notifications. If the listener is already registered, no change occurs.

Parameters

listener:Object - An object with onKeyDown and onKeyUp methods.

Example

The following example creates a new listener object and defines a function for onKeyDown and onKeyUp. The last line uses addListener() to register the listener with the Key object so that it can receive notification from the key down and key up events.

var myListener:Object = new Object();
myListener.onKeyDown = function () {
    trace ("You pressed a key.");
}
myListener.onKeyUp = function () {
    trace ("You released a key.");
}
Key.addListener(myListener);

See also

getCode (Key.getCode method), isDown (Key.isDown method), onKeyDown (Key.onKeyDown event listener), onKeyUp (Key.onKeyUp event listener), removeListener (Key.removeListener method)