Table of Contents

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


Table of Contents