User Guide

582 Chapter 2: ActionScript Language Reference
MovieClip.swapDepths()
Availability
Flash Player 5.
Usage
my_mc.swapDepths(depth:Number)
my_mc.swapDepths(target:String)
Parameters
depth
A number specifying the depth level where my_mc is to be placed.
target A string specifying the movie clip instance whose depth is swapped by the instance
specified by
my_mc. Both instances must have the same parent movie clip.
Returns
Nothing.
Description
Method; swaps the stacking, or z-order (depth level), of the specified instance (my_mc) with the
movie clip specified by the
target parameter, or with the movie clip that currently occupies the
depth level specified in the
depth parameter. Both movie clips must have the same parent movie
clip. Swapping the depth level of movie clips has the effect of moving one movie clip in front of or
behind the other. If a movie clip is tweening when this method is called, the tweening is stopped.
For more information, see “Managing movie clip depths” in Using ActionScript in Flash.
You can extend the methods and event handlers of the MovieClip class by creating a subclass. For
more information, see “Assigning a class to a movie clip symbol” in Using ActionScript in Flash.
Example
The following example swaps the stacking order of two movie clip instances. Overlap two movie
clip instances on the Stage, called
myMC1_mc and myMC2_mc and then add the following
ActionScript to your AS or FLA file:
myMC1_mc.onRelease = function() {
this.swapDepths(myMC2_mc);
};
myMC2_mc.onRelease = function() {
this.swapDepths(myMC1_mc);
};
See also
_level, MovieClip.getDepth(), MovieClip.getInstanceAtDepth(),
MovieClip.getNextHighestDepth()