View comments | RSS feed

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()

Comments


Firetron said on Oct 27, 2004 at 1:43 PM :
In the second usage, target must be a movieclip, not a string.

my_mc.swapDepths(target:String)
should be
my_mc.swapDepths(target:MovieClip)

The example shown correctly passes movieclips.
If you were to call
this.swapDepths(myMC2_mc._name);
it would fail to swap.
No screen name said on Aug 29, 2005 at 2:48 PM :
swapDepths seems to fail if you access a clip reference stored in a class and try to swap from outside the class. i.e.

someClassWithAMovieClip.getMc.swapDepths(10);

where someClassWithAMovieClip has a method

public function getMc () : MovieClip
{
return this.clip;
}
No screen name said on Aug 29, 2005 at 2:50 PM :
above post should have read

someClassWithAMovieClip.getMc().swapDepths(10);

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001556.html