Table of Contents

Key.removeListener( ) Method Flash 6

cancels event notices for the specified listener
Key.removeListener(listener)

Arguments

listener

An object that was previously registered as a listener for Key using Key.addListener( )

Returns

A Boolean; true if listener was found and removed, false if listener was not registered as an event listener for Key. The return value is useful for debugging code that removes listeners.

Description

The removeListener( ) method stops listener from receiving Key event notifications. It should be used only after listener has been registered as an event listener via addListener( ). The listener object is not deleted but can be removed and added repeatedly.

Example

Event listeners should be removed when the task they perform is no longer required. For example, when a modal dialog box is displayed in a keyboard-controlled application, the application should ignore general keyboard input until the dialog box is closed. We can disable keyboard input outside the dialog box by removing the default key listener for the application, as shown here:

// Method definition for launching a dialog box from theApp
theApp.displayModalDialog = function () {
  // Disable the regular key listener
  Key.removeListener(this.defaultKeyListener);
  // Enable the temporary modal dialog key listener
  Key.addListener(this.modalKeyListener);
  // Continue with launching the dialog...
}

See Also

Key.addListener( ), Key.onKeyDown( ), Key.onKeyUp( ); Chapter 10


Table of Contents