View comments | RSS feed

MovieClip.getNextHighestDepth()

Availability

Flash Player 7.

Usage

my_mc.getNextHighestDepth() : Number

Parameters

None.

Returns

An integer that reflects the next available depth index that would render above all other objects on the same level and layer within my_mc.

Description

Method; lets you determine a depth value that you can pass to MovieClip.attachMovie(), MovieClip.duplicateMovieClip(), or MovieClip.createEmptyMovieClip() to ensure that Flash renders the movie clip in front of all other objects on the same level and layer in the current movie clip. The value returned is 0 or higher (that is, negative numbers are not returned).

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 creates a new movie clip instance, logo_mc, at the next highest depth available. At runtime, logo_mc renders in front of all other instances at the same level.

this.createEmptyMovieClip("logo_mc", this.getNextHighestDepth());
var logo_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadInit = function(target_mc:MovieClip) {
   target_mc.onPress = function() {
      this.startDrag();
   };
   target_mc.onRelease = function() {
      this.stopDrag();
   };
};
logo_mcl.addListener(mclListener);
logo_mcl.loadClip("http://www.macromedia.com/devnet/blueprint/articles/nielsen/spotlight_jnielsen.jpg", logo_mc);

See also

MovieClip.getDepth(), MovieClip.getInstanceAtDepth(), MovieClip.swapDepths()

Comments


TroyWorks said on Aug 26, 2004 at 2:02 AM :
one should be careful useing getNextHighestDepth on the _root. Else you can run into protected ranges that seem to loadMovies fine but removeMovieClip() won't work on!
Francis Cheng said on Aug 26, 2004 at 11:01 AM :
Thanks for pointing out this issue. This happens when a V2 Component is on the stage or in the library.
The following technote describes workarounds for this issue:
http://www.macromedia.com/support/flash/ts/documents/remove_mc_depth.htm
brilliantnut said on Apr 8, 2005 at 2:47 AM :
Its interesting to note that the availability of getNextHighestDepth() is only FlashPlayer 7, whereas many of the examples in this help document for items which have availability Flash Player 6, contain getNextHighestDepth() in them. Were these docs completely re-written after the release of Flash Player 7, that all the examples have the use of getNextHighestDepth, or were the help-doc writers at Macromedia prescient to know that Player 7 will have something like this in the future?. I think that Macromedia should also provide an alternative way of finding out the highest depth, if one is publishing for player 6 or lower.

If you are publishing the movies for Flash Player 6, then the use of getNextHighestDepth will have pretty strange effects. Only the first movie will be attached and the subsequent ones will not be attached. This caused nearly two days of consternation for our team, before we figured out that the getNextHighestDepth function was the culprit.
oopiewanCodeknowbie said on Aug 24, 2005 at 4:31 PM :
I had an issue with this function where it just "all of a sudden" stopped working. A guy had sent me a fla with several symbols. What he was trying to do with buttons and the timeline, I was doing in code. So I deleted several symbols in his library.
I am not sure if this is what caused the function to stop working but what I did was do a quick test with _root.getNextHigestDepth and it worked. The bad fla did not work when all but the test code was commented out.
I then created a new fla file and copied all the symbols into it and pasted the code into the root timeline and it just started working again.
If the function just stops working for youl, try something along those lines and see if it starts working again.

 

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/00001507.html