Stage.removeListener( ) Method

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
Stage.removeListener( ) Method Flash 6

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

Arguments

listener

An object that was previously registered as a listener for Stage.

Returns

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

Description

The removeListener( ) method stops listener from receiving Stage 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 it can be removed and added repeatedly. To delete a listener, first remove it with removeListener( ) and then delete it with the delete operator.

Example

You should remove event listeners when the task they perform is no longer required. For example, a text field might have two display settings in an application, "percentage width" (stretch the field to match the movie width) and "fixed width" (stay the same width). A listener could be added to, or removed from, the field, depending on the current mode, as follows:

// Set scaleMode to allow onResize( ) to operate. Stage.align = "LT"; Stage.scaleMode = "noScale";     // Create the text field. this.createTextField("body_txt", 1, 5, 0, 200, 20); body_txt.border = true; body_txt.type = "input"; body_txt.onResize = function () {   this._width = Stage.width - 10; };     // Mode-switching function. Adds and removes the listener dynamically. function setEditMode (mode) {   if (mode =  = "fixed") {     Stage.removeListener(body_txt);   } else if (mode =  = "percent") {     Stage.addListener(body_txt);   } }     // Set the mode. setEditMode("percent");

See Also

Stage.addListener( ), Stage.onResize( ); Chapter 10



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net