Key.addlistener() - MACROMEDIA FLASH MX 2004-ACTIONSCRIPT LANGUAGE Reference

Actionscript language reference
Table of Contents

Advertisement

Key.addListener()

Availability
Flash Player 6.
Usage
Key.addListener (newListener:Object) : Void
Parameters
newListener
Returns
Nothing.
Description
Method; registers an object to receive
pressed or released, regardless of the input focus, all listening objects registered with
addListener()
objects can listen for keyboard notifications. If the listener
change occurs.
Example
The following example creates a new listener object and defines a function for
. The last line uses
onKeyUp
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);
The following example assigns the keyboard shortcut Control+7 to a button with an instance
name of
my_btn
_accProps). In this example, when you press Control+7 the
in the Output panel.
hello
function myOnPress() {
trace("hello");
}
function myOnKeyDown() {
// 55 is key code for 7
if (Key.isDown(Key.CONTROL) && Key.getCode() == 55) {
Selection.setFocus(my_btn);
my_btn.onPress();
}
}
var myListener:Object = new Object();
An object with methods
onKeyDown
have either their
onKeyDown
addListener()
and makes information about the shortcut available to screen readers (see
and
onKeyDown
onKeyUp
and
onKeyUp
method or
onKeyUp
newListener
to register the listener with the Key object so that it
myOnPress
.
notification. When a key is
method invoked. Multiple
is already registered, no
onKeyDown
function displays the text
Key.addListener()
and
343

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash mx

Table of Contents