Addlistener (Key.addlistener Method) - MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE Reference

Actionscript 2.0 language reference
Table of Contents

Advertisement

addListener (Key.addListener method)

public static addListener(listener:Object) : Void
Registers an object to receive
released, regardless of the input focus, all listening objects registered with
have either their
onKeyDown
for keyboard notifications. If the listener
A Flash application can only monitor keyboard events that occur within its focus. A Flash
application cannot detect keyboard events in another application.
Availability: ActionScript 1.0; Flash Player 6
Parameters
- An object with methods
listener:Object
Example
The following example creates a new listener object and defines a function for
. The last line uses
onKeyUp
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);
The following example assigns the keyboard shortcut Control+7 to a button with an instance
name of
and makes information about the shortcut available to screen readers (see
my_btn
). In this example, when you press Control+7 the
_accProps
text
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();
myListener.onKeyDown = myOnKeyDown;
672
ActionScript classes
and
onKeyDown
onKeyUp
method or
onKeyUp
newListener
onKeyDown
to register the listener with the Key object so that
addListener()
notification. When a key is pressed or
method invoked. Multiple objects can listen
is already registered, no change occurs.
and
onKeyUp
myOnPress
addListener()
.
and
onKeyDown
function displays the

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

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

This manual is also suitable for:

Flash 8

Table of Contents

Save PDF