Properties | Events | Methods |
Object
Player version: | Flash Player 6 |
A Flash application can only monitor keyboard events that occur within its focus. A Flash application cannot detect keyboard events in another application.
Property Summary | |
static | BACKSPACE : Number
The key code value for the Backspace key (8). |
static | CAPSLOCK : Number
The key code value for the Caps Lock key (20). |
static | CONTROL : Number
The key code value for the Control key (17). |
static | DELETEKEY : Number
The key code value for the Delete key (46). |
static | DOWN : Number
The key code value for the Down Arrow key (40). |
static | END : Number
The key code value for the End key (35). |
static | ENTER : Number
The key code value for the Enter key (13). |
static | ESCAPE : Number
The key code value for the Escape key (27). |
static | HOME : Number
The key code value for the Home key (36). |
static | INSERT : Number
The key code value for the Insert key (45). |
static | LEFT : Number
The key code value for the Left Arrow key (37). |
static | _listeners : Array [read-only]A list of references to all listener objects that are registered with the Key object. |
static | PGDN : Number
The key code value for the Page Down key (34). |
static | PGUP : Number
The key code value for the Page Up key (33). |
static | RIGHT : Number
The key code value for the Right Arrow key (39). |
static | SHIFT : Number
The key code value for the Shift key (16). |
static | SPACE : Number
The key code value for the Spacebar (32). |
static | TAB : Number
The key code value for the Tab key (9). |
static | UP : Number
The key code value for the Up Arrow key (38). |
Properties inherited from class Object |
__proto__, __resolve, constructor, prototype |
Event Summary | |
onKeyDown = function() {}
Notified when a key is pressed. |
|
onKeyUp = function() {}
Notified when a key is released. |
Method Summary | |
static | addListener(listener:Object) : Void
Registers an object to receive onKeyDown and onKeyUp notification. |
static | getAscii() : Number
Returns the ASCII code of the last key pressed or released. |
static | getCode() : Number
Returns the key code value of the last key pressed. |
static | isAccessible() : Boolean
Returns a Boolean value indicating, depending on security restrictions, whether the last key pressed may be accessed by other SWF files. |
static | isDown(code:Number) : Boolean
Returns true if the key specified in keycode is pressed; false otherwise. |
static | isToggled(code:Number) : Boolean
Returns true if the Caps Lock or Num Lock key is activated (toggled to an active state); false otherwise. |
static | removeListener(listener:Object) : Boolean
Removes an object previously registered with Key.addListener() . |
Methods inherited from class Object |
addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch |
Property Detail |
public static BACKSPACE : Number
Player version: | Flash Player 5 |
onKeyDown
. The last line uses addListener()
to register the listener with the Key object so that it can receive notification from the key down event. var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.BACKSPACE)) { trace("you pressed the Backspace key."); } else { trace("you DIDN'T press the Backspace key."); } }; Key.addListener(keyListener);
When you use this example, be sure to select Control > Disable Keyboard Shortcuts in the test environment.
public static CAPSLOCK : Number
Player version: | Flash Player 5 |
onKeyDown
. The last line uses addListener()
to register the listener with the Key object so that it can receive notification from the key down event. var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.CAPSLOCK)) { trace("you pressed the Caps Lock key."); trace("\tCaps Lock == "+Key.isToggled(Key.CAPSLOCK)); } }; Key.addListener(keyListener);
Information is displayed in the Output panel when you press the Caps Lock key. The Output panel displays either true
or false
, depending on whether the Caps Lock key is activated using the isToggled method. Information is written to the log file when you press the Caps Lock key. The log file writes either true
or false
, depending on whether the Caps Lock is activated using the isToggled()
method.
public static CONTROL : Number
Player version: | Flash Player 5 |
my_btn
and makes information about the shortcut available to screen readers (see _accProps
). In this example, when you press Control+7 the myOnPress
function displays the text hello
in the Output panel. In this example, when you press Control+7 the myOnPress
function writes the text "hello" to the log file. 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; Key.addListener(myListener); my_btn.onPress = myOnPress; my_btn._accProps.shortcut = "Ctrl+7"; Accessibility.updateProperties();
public static DELETEKEY : Number
Player version: | Flash Player 5 |
this.createEmptyMovieClip("canvas_mc", this.getNextHighestDepth()); var mouseListener:Object = new Object(); mouseListener.onMouseDown = function() { this.drawing = true; canvas_mc.moveTo(_xmouse, _ymouse); canvas_mc.lineStyle(3, 0x99CC00, 100); }; mouseListener.onMouseUp = function() { this.drawing = false; }; mouseListener.onMouseMove = function() { if (this.drawing) { canvas_mc.lineTo(_xmouse, _ymouse); } updateAfterEvent(); }; Mouse.addListener(mouseListener); // var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.DELETEKEY) || Key.isDown(Key.BACKSPACE)) { canvas_mc.clear(); } }; Key.addListener(keyListener);
When you use this example, be sure to select Control > Disable Keyboard Shortcuts in the test environment.
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
public static DOWN : Number
Player version: | Flash Player 5 |
car_mc
a constant distance (10) when you press an arrow key. A sound plays when you press the Spacebar. Give a sound in the library a linkage identifier of horn_id
for this example. var DISTANCE:Number = 10; var horn_sound:Sound = new Sound(); horn_sound.attachSound("horn_id"); var keyListener_obj:Object = new Object(); keyListener_obj.onKeyDown = function() { switch (Key.getCode()) { case Key.SPACE : horn_sound.start(); break; case Key.LEFT : car_mc._x -= DISTANCE; break; case Key.UP : car_mc._y -= DISTANCE; break; case Key.RIGHT : car_mc._x += DISTANCE; break; case Key.DOWN : car_mc._y += DISTANCE; break; } }; Key.addListener(keyListener_obj);
public static END : Number
Player version: | Flash Player 5 |
public static ENTER : Number
Player version: | Flash Player 5 |
car_mc
a constant distance (10) when you press an arrow key. The car_mc
instance stops when you press Enter and deletes the onEnterFrame
event. var DISTANCE:Number = 5; var keyListener:Object = new Object(); keyListener.onKeyDown = function() { switch (Key.getCode()) { case Key.LEFT : car_mc.onEnterFrame = function() { this._x -= DISTANCE; }; break; case Key.UP : car_mc.onEnterFrame = function() { this._y -= DISTANCE; }; break; case Key.RIGHT : car_mc.onEnterFrame = function() { this._x += DISTANCE; }; break; case Key.DOWN : car_mc.onEnterFrame = function() { this._y += DISTANCE; }; break; case Key.ENTER : delete car_mc.onEnterFrame; break; } }; Key.addListener(keyListener);
When you use this example, be sure to select Control > Disable Keyboard Shortcuts in the test environment.
public static ESCAPE : Number
Player version: | Flash Player 5 |
var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.ESCAPE)) { // Get the current timer, convert the value to seconds and round it to two decimal places. var timer:Number = Math.round(getTimer()/10)/100; trace("you pressed the Esc key: "+getTimer()+" ms ("+timer+" s)"); } }; Key.addListener(keyListener);
When you use this example, be sure to select Control > Disable Keyboard Shortcuts in the test environment.
public static HOME : Number
Player version: | Flash Player 5 |
car_mc
at the x and y coordinates of 0,0. When you press the Home key, car_mc
returns to 0,0. Create a movie clip that has a linkage ID car_id
, and add the following ActionScript to Frame 1 of the Timeline: this.attachMovie("car_id", "car_mc", this.getNextHighestDepth(), {_x:0, _y:0}); car_mc.onPress = function() { this.startDrag(); }; car_mc.onRelease = function() { this.stopDrag(); }; var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.HOME)) { car_mc._x = 0; car_mc._y = 0; } }; Key.addListener(keyListener);
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
public static INSERT : Number
Player version: | Flash Player 5 |
onKeyDown
. The last line uses addListener()
to register the listener with the Key object so that it can receive notification from the key down event and write information to the log file. The last line uses addListener()
to register the listener with the Key object so that it can receive notification from the key down event and display information in the Output panel. var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.INSERT)) { trace("You pressed the Insert key."); } }; Key.addListener(keyListener);
public static LEFT : Number
Player version: | Flash Player 5 |
car_mc
a constant distance (10) when you press an arrow key. A sound plays when you press the Spacebar. Give a sound in the library a linkage identifier of horn_id
for this example. var DISTANCE:Number = 10; var horn_sound:Sound = new Sound(); horn_sound.attachSound("horn_id"); var keyListener_obj:Object = new Object(); keyListener_obj.onKeyDown = function() { switch (Key.getCode()) { case Key.SPACE : horn_sound.start(); break; case Key.LEFT : car_mc._x -= DISTANCE; break; case Key.UP : car_mc._y -= DISTANCE; break; case Key.RIGHT : car_mc._x += DISTANCE; break; case Key.DOWN : car_mc._y += DISTANCE; break; } }; Key.addListener(keyListener_obj);
public static _listeners : Array
[read-only]
Player version: | Flash Player 6 |
addListener()
and removelistener()
methods.
Example
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
public static PGDN : Number
Player version: | Flash Player 5 |
car_mc
when you press the Page Down or Page Up key. var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.PGDN)) { car_mc._rotation += 5; } else if (Key.isDown(Key.PGUP)) { car_mc._rotation -= 5; } }; Key.addListener(keyListener);
public static PGUP : Number
Player version: | Flash Player 5 |
car_mc
when you press the Page Down or Page Up key. var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.PGDN)) { car_mc._rotation += 5; } else if (Key.isDown(Key.PGUP)) { car_mc._rotation -= 5; } }; Key.addListener(keyListener);
public static RIGHT : Number
Player version: | Flash Player 5 |
car_mc
a constant distance (10) when you press an arrow key. A sound plays when you press the Spacebar. For this example, give a sound in the library a linkage identifier of horn_id
. var DISTANCE:Number = 10; var horn_sound:Sound = new Sound(); horn_sound.attachSound("horn_id"); var keyListener_obj:Object = new Object(); keyListener_obj.onKeyDown = function() { switch (Key.getCode()) { case Key.SPACE : horn_sound.start(); break; case Key.LEFT : car_mc._x -= DISTANCE; break; case Key.UP : car_mc._y -= DISTANCE; break; case Key.RIGHT : car_mc._x += DISTANCE; break; case Key.DOWN : car_mc._y += DISTANCE; break; } }; Key.addListener(keyListener_obj);
public static SHIFT : Number
Player version: | Flash Player 5 |
car_mc
when you press Shift. var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.SHIFT)) { car_mc._xscale = 2; car_mc._yscale = 2; } else if (Key.isDown(Key.CONTROL)) { car_mc._xscale /= 2; car_mc._yscale /= 2; } }; Key.addListener(keyListener);
public static SPACE : Number
Player version: | Flash Player 5 |
car_mc
a constant distance (10) when you press an arrow key. A sound plays when you press the Spacebar. For this example, give a sound in the library a linkage identifier of horn_id
. var DISTANCE:Number = 10; var horn_sound:Sound = new Sound(); horn_sound.attachSound("horn_id"); var keyListener_obj:Object = new Object(); keyListener_obj.onKeyDown = function() { switch (Key.getCode()) { case Key.SPACE : horn_sound.start(); break; case Key.LEFT : car_mc._x -= DISTANCE; break; case Key.UP : car_mc._y -= DISTANCE; break; case Key.RIGHT : car_mc._x += DISTANCE; break; case Key.DOWN : car_mc._y += DISTANCE; break; } }; Key.addListener(keyListener_obj);
public static TAB : Number
Player version: | Flash Player 5 |
this.createTextField("date_txt", this.getNextHighestDepth(), 0, 0, 100, 22); date_txt.autoSize = true; var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.TAB)) { var today_date:Date = new Date(); date_txt.text = today_date.toString(); } }; Key.addListener(keyListener);
When you use this example, be sure to select Control > Disable Keyboard Shortcuts in the test environment.
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
public static UP : Number
Player version: | Flash Player 5 |
car_mc
a constant distance (10) when you press an arrow key. A sound plays when you press the Spacebar. For this example, give a sound in the library a linkage identifier of horn_id
. var DISTANCE:Number = 10; var horn_sound:Sound = new Sound(); horn_sound.attachSound("horn_id"); var keyListener_obj:Object = new Object(); keyListener_obj.onKeyDown = function() { switch (Key.getCode()) { case Key.SPACE : horn_sound.start(); break; case Key.LEFT : car_mc._x -= DISTANCE; break; case Key.UP : car_mc._y -= DISTANCE; break; case Key.RIGHT : car_mc._x += DISTANCE; break; case Key.DOWN : car_mc._y += DISTANCE; break; } }; Key.addListener(keyListener_obj);
Event Detail |
public onKeyDown = function() {}
Player version: | Flash Player 6 |
onKeyDown
, you must create a listener object. You can then define a function for onKeyDown
and use addListener()
to register the listener with the 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.
A Flash application can only monitor keyboard events that occur within its focus. A Flash application cannot detect keyboard events in another application.
See alsoKey.addListener() |
public onKeyUp = function() {}
Player version: | Flash Player 6 |
onKeyUp
, you must create a listener object. You can then define a function for onKeyUp
and use addListener()
to register the listener with the 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.
A Flash application can only monitor keyboard events that occur within its focus. A Flash application cannot detect keyboard events in another application.
See alsoKey.addListener() |
Method Detail |
public static addListener(listener:Object) : Void
Player version: | Flash Player 6 |
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. A Flash application can only monitor keyboard events that occur within its focus. A Flash application cannot detect keyboard events in another application.
Parameterslistener:Object — An object with methods onKeyDown and onKeyUp . |
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. 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
and makes information about the shortcut available to screen readers (see _accProps
). In this example, when you press Control+7 the myOnPress
function displays the text hello
in the Output panel. In this example, when you press Control+7 the myOnPress
function writes the text "hello" to the log file.
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; Key.addListener(myListener); my_btn.onPress = myOnPress; my_btn._accProps.shortcut = "Ctrl+7"; Accessibility.updateProperties();
Key.getCode(), Key.isDown(), Key.onKeyDown, Key.onKeyUp, Key.removeListener() |
public static getAscii() : Number
Player version: | Flash Player 5 |
Key.getAscii()
returns @
on a Japanese keyboard, which is the same as it does on an English keyboard. A Flash application can only monitor keyboard events that occur within its focus. A Flash application cannot detect keyboard events in another application.
ReturnsNumber —
The ASCII value of the last key pressed. This method returns 0 if no key was pressed or released, or if the key code is not accessible for security reasons.
|
getAscii()
method any time a key is pressed. The example creates a listener object named keyListener
and defines a function that responds to the onKeyDown
event by calling Key.getAscii()
.The keyListener
object is then registered to the Key
object, which broadcasts the onKeyDown
message whenever a key is pressed while the SWF file plays. var keyListener:Object = new Object(); keyListener.onKeyDown = function() { trace("The ASCII code for the last key typed is: "+Key.getAscii()); }; Key.addListener(keyListener);
When you use this example, be sure to select Control > Disable Keyboard Shortcuts in the test environment.
The following example adds a call to Key.getAscii()
to show how the two methods differ. The main difference is that Key.getAscii()
differentiates between uppercase and lowercase letters, and Key.getCode()
does not.
var keyListener:Object = new Object(); keyListener.onKeyDown = function() { trace("For the last key typed:"); trace("\tThe Key code is: "+Key.getCode()); trace("\tThe ASCII value is: "+Key.getAscii()); trace(""); }; Key.addListener(keyListener);
When you use this example, be sure to select Control > Disable Keyboard Shortcuts in the test environment.
See alsoKey.isAccessible() |
public static getCode() : Number
Player version: | Flash Player 5 |
Note: The Flash Lite implementation of this method returns a string or a number, depending on the key code passed in by the platform. The only valid key codes are the standard key codes accepted by this class and the special key codes listed as properties of the ExtendedKey
class.
A Flash application can only monitor keyboard events that occur within its focus. A Flash application cannot detect keyboard events in another application.
ReturnsNumber —
The key code of the last key pressed. This method returns 0 if no key was pressed or released, or if the key code is not accessible for security reasons.
|
getCode()
method any time a key is pressed. The example creates a listener object named keyListener
and defines a function that responds to the onKeyDown
event by calling Key.getCode()
. The keyListener
object is then registered to the Key
object, which broadcasts the onKeyDown
message whenever a key is pressed while the SWF file plays. var keyListener:Object = new Object(); keyListener.onKeyDown = function() { // compare return value of getCode() to constant if (Key.getCode() == Key.ENTER) { trace ("Virtual key code: "+Key.getCode()+" (ENTER key)"); } else { trace("Virtual key code: "+Key.getCode()); } }; Key.addListener(keyListener);
When you use this example, be sure to select Control > Disable Keyboard Shortcuts in the test environment.
The following example adds a call to Key.
getAscii()
to show how the two methods differ. The main difference is that Key.
getAscii()
differentiates between uppercase and lowercase letters, and Key.getCode()
does not.
var keyListener:Object = new Object(); keyListener.onKeyDown = function() { trace("For the last key typed:"); trace("\tThe Key code is: "+Key.getCode()); trace("\tThe ASCII value is: "+Key.getAscii()); trace(""); }; Key.addListener(keyListener);
When you use this example, be sure to select Control > Disable Keyboard Shortcuts in the test environment.
See alsoKey.getAscii, Key.isAccessible() |
public static isAccessible() : Boolean
Player version: | Flash Player 8 |
Boolean —
The value true if the last key pressed may be accessed. If access is not permitted, this method returns false .
|
public static isDown(code:Number) : Boolean
Player version: | Flash Player 5 |
true
if the key specified in keycode
is pressed; false
otherwise. On the Macintosh, the key code values for the Caps Lock and Num Lock keys are identical. A Flash application can only monitor keyboard events that occur within its focus. A Flash application cannot detect keyboard events in another application.
Parameterscode:Number — The key code value assigned to a specific key or a Key class property associated with a specific key. |
Boolean —
The value true if the key specified in keycode is pressed; false otherwise.
|
car_mc
) location: car_mc.onEnterFrame = function() {
if (Key.isDown(Key.RIGHT)) {
this._x += 10;
} else if (Key.isDown(Key.LEFT)) {
this._x -= 10;
}
};
public static isToggled(code:Number) : Boolean
Player version: | Flash Player 5 |
true
if the Caps Lock or Num Lock key is activated (toggled to an active state); false
otherwise. Although the term toggled usually means that something is switched between two options, the method Key.isToggled() will only return true
if the key is toggled to an active state. On the Macintosh, the key code values for the Caps Lock and Num Lock keys are identical. A Flash application can only monitor keyboard events that occur within its focus. A Flash application cannot detect keyboard events in another application.
Parameterscode:Number — The key code for the Caps Lock key (20) or the Num Lock key (144). |
Boolean —
The value true if the Caps Lock or Num Lock key is activated (toggled to an active state); false otherwise.
|
isToggled()
method any time a key is pressed and executes a trace statement any time the Caps Lock key is toggled to an active state. The example creates a listener object named keyListener
and defines a function that responds to the onKeyDown
event by calling Key.isToggled()
. The keyListener
object is then registered to the Key
object, which broadcasts the onKeyDown
message whenever a key is pressed while the SWF file plays. var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.CAPSLOCK)) { trace("you pressed the Caps Lock key."); trace("\tCaps Lock == "+Key.isToggled(Key.CAPSLOCK)); } }; Key.addListener(keyListener);
Information displays in the Output panel when you press the Caps Lock key. Information is written to the log file when you press the Caps Lock key. The Output panel displays either true
or false
, depending on whether the Caps Lock is activated using the isToggled method. The log file writes either true
or false
, depending on whether the Caps Lock is activated using the isToggled method.
The following example creates two text fields that update when the Caps Lock and Num Lock keys are toggled. Each text field displays true when the key is activated, and false when the key is deactivated.
this.createTextField("capsLock_txt", this.getNextHighestDepth(), 0, 0, 100, 22); capsLock_txt.autoSize = true; capsLock_txt.html = true; this.createTextField("numLock_txt", this.getNextHighestDepth(), 0, 22, 100, 22); numLock_txt.autoSize = true; numLock_txt.html = true; // var keyListener:Object = new Object(); keyListener.onKeyDown = function() { capsLock_txt.htmlText = "<b>Caps Lock:</b> "+Key.isToggled(Key.CAPSLOCK); numLock_txt.htmlText = "<b>Num Lock:</b> "+Key.isToggled(144); }; Key.addListener(keyListener);
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
public static removeListener(listener:Object) : Boolean
Player version: | Flash Player 6 |
Key.addListener()
.
Parameters
listener:Object — An object. |
Boolean —
If the listener was successfully removed, the method returns true . If the listener was not successfully removed (for example, because the listener was not on the Key object's listener list), the method returns false .
|
car_mc
using the Left and Right arrow keys. The listener is removed when you press Escape, and car_mc
no longer moves. var keyListener:Object = new Object(); keyListener.onKeyDown = function() { switch (Key.getCode()) { case Key.LEFT : car_mc._x -= 10; break; case Key.RIGHT : car_mc._x += 10; break; case Key.ESCAPE : Key.removeListener(keyListener); } }; Key.addListener(keyListener);
Properties | Events | Methods |