Flash Lite 2.x and 3.0 ActionScript Language Reference

removeListener (Key.removeListener method)

public static removeListener(listener:Object) : Boolean

Removes an object previously registered with Key.addListener().

Parameters

listener:Object - An object.

Returns

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 objects listener list), the method returns false.

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);