User Guide
Key.removeListener() 365
Key.removeListener()
Availability
Flash Player 6.
Usage
Key.removeListener (listener:Object) : Boolean
Parameters
listener
An object.
Returns
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.
Description
Method; removes an object previously registered with Key.addListener().
Example
The following example moves a movie clip called 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);