G-L > Key.addListener |
![]() ![]() ![]() |
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
This example creates a new listener object and defines a function for onKeyDown
and onKeyUp
. The last line uses the addListener
method 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);
![]() ![]() ![]() |