Managing movie clip depths 367
Determining the next highest available depth
To determine the next highest available depth within a movie clip, use
MovieClip.getNextHighestDepth(). The integer value returned by this method indicates
the next available depth that will render in front of all other objects in the movie clip.
The following code attaches a new movie clip, with a depth value of 10, on the root timeline
named
file_mc. It then determines the next highest available depth in that same movie clip
and creates a new movie clip called
edit_mc at that depth.
this.attachMovie("menuClip","file_mc", 10, {_x:0, _y:0});
trace(file_mc.getDepth()); // 10
var nextDepth:Number = this.getNextHighestDepth();
this.attachMovie("menuClip", "edit_mc", nextDepth, {_x:200, _y:0});
trace(edit_mc.getDepth()); // 11
In this case, the variable named nextDepth contains the value 11 because that’s the next
highest available depth for the
edit_mc movie clip.
Do not use
MovieClip.getNextHighestDepth() with components; instead, use the depth
manager. For more information, see “DepthManager class” in the Component Language
Reference. For more information on
MovieClip.getNextHighestDepth(), see
getNextHighestDepth (MovieClip.getNextHighestDepth method).
To obtain the current highest occupied depth, subtract 1 from the value that
getNextHighestDepth() returns, as shown in the next section.
Determining the instance at a particular depth
To determine the instance at a particular depth, use MovieClip.getInstanceAtDepth().
This method returns a reference to the MovieClip instance at the specified depth.
The following code combines
getNextHighestDepth() and getInstanceAtDepth() to
determine the movie clip at the (current) highest occupied depth on the root timeline.
var highestOccupiedDepth:Number = this.getNextHighestDepth() - 1;
var instanceAtHighestDepth:MovieClip =
this.getInstanceAtDepth(highestOccupiedDepth);
For more information, see getInstanceAtDepth (MovieClip.getInstanceAtDepth
method)
in the ActionScript 2.0 Language Reference.