_listeners (Key._listeners property)
public static _listeners :
A list of references to all listener objects registered with the Key object. This property is
intended for internal use, but may be useful if you want to ascertain the number of listeners
currently registered with the Key object. Objects are added and removed from this array by
calls to the addListener() and removelistener() methods.
Availability: ActionScript 1.0; Flash Lite 2.0
Example
The following example shows how to use the length property to ascertain the number of
listener objects currently registered to the Key object.
var myListener:Object = new Object();
myListener.onKeyDown = function () {
trace ("You pressed a key.");
}
Key.addListener(myListener);
trace(Key._listeners.length); // Output: 1
onKeyDown (Key.onKeyDown event listener)
onKeyDown = function() {}
Notified when a key is pressed. To use
then define a function for
Key object, as shown in the following example:
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
trace("DOWN -> Code: "+Key.getCode()+"\tACSII: "+Key.getAscii()+"\tKey:
"+chr(Key.getAscii()));
};
keyListener.onKeyUp = function() {
trace("UP -> Code: "+Key.getCode()+"\tACSII: "+Key.getAscii()+"\tKey:
"+chr(Key.getAscii()));
};
Key.addListener(keyListener);
Listeners enable different pieces of code to cooperate because multiple listeners can receive
notification about a single event.
Availability: ActionScript 1.0; Flash Lite 2.0
See also
addListener (Key.addListener method)
Array
[read-only]
onKeyDown
and use
onKeyDown
addListener()
, you must create a listener object. You can
to register the listener with the
Key
383