Stage.addListener( ) Method

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

registers an object to receive onResize( ) events
Stage.addListener(listener)

Arguments

listener

An object with an onResize( ) method defined.

Description

The addListener( ) method adds listener to the list of objects notified when Stage's onResize( ) event occurs. The listener argument is an object of any class that defines a method by the name onResize; the method is invoked when the corresponding event occurs for Stage. Instances of built-in classes, such as TextField, Button, or MovieClip, can all respond to Stage.onResize( ). To stop a listener object from receiving events, use Stage.removeListener( ).

Multiple objects can respond independently to the onResize( ) listener event. When multiple listeners are registered to Stage, their methods are invoked in the order the listeners were added.

For general information on how listeners work, see Chapter 10.

Example

The following code assigns an onResize( ) method to the ball_mc movie clip and registers the clip to respond to the onResize( ) event. Note that Stage.scaleMode must be set to "noScale" in order for the onResize( ) event to be triggered:

Stage.align = "LT"; Stage.scaleMode = "noScale"; ball_mc.onResize = function () {   // Place ball_mc in the center of the Stage (assumes that   // ball_mc's content is centered on its registration point).   // Inside the method, 'this' refers to ball_mc.   this._x = Stage.width/2;   this._y = Stage.height/2; } Stage.addListener(ball_mc);

See Also

Stage.onResize( ), Stage.removeListener( ), Stage.scaleMode; 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