EasyManua.ls Logo

MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT - Page 409

MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT
816 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Key.addListener() 409
Listener summary for the Key class
Key.addListener()
Availability
Flash Player 6.
Usage
Key.addListener (newListener)
Parameters
newListener
An object with methods onKeyDown and onKeyUp.
Returns
Nothing.
Description
Method; 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 onKeyUp method invoked. Multiple
objects can listen for keyboard notifications. If the listener
newListener is already registered, no
change occurs.
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.
myListener = new Object();
myListener.onKeyDown = function () {
trace ("You pressed a key.");
}
myListener.onKeyUp = function () {
trace ("You released a key.");
}
Key.addListener(myListener);
Key.RIGHT Constant associated with the key code value for the Right Arrow key (39).
Key.SHIFT Constant associated with the key code value for the Shift key (16).
Key.SPACE Constant associated with the key code value for the Spacebar (32).
Key.TAB Constant associated with the key code value for the Tab key (9).
Key.UP Constant associated with the key code value for the Up Arrow key (38).
Method Description
Key.onKeyDown Notified when a key is pressed.
Key.onKeyUp Notified when a key is released.
Property Description

Table of Contents

Related product manuals