Stage.removeListener( ) Method | Flash 6 |
cancels event notices for the specified listener |
An object that was previously registered as a listener for Stage.
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.
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.
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");
Stage.addListener( ), Stage.onResize( ); Chapter 10