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 creates a new movie clip, with a depth value of 10, on the Timeline of the movie clip named menus_mc. It then determines the next highest available depth in that same movie clip, and creates a new movie clip at that depth.

menus_mc.attachMovie("menuClip","file_menu", 10);
var nextDepth = menus_mc.getNextHighestDepth();
menus_mc.attachMovie("menuClip", "edit_menu", nextDepth);

In this case, the variable named nextDepth contains the value 11, because that's the next highest available depth for the movie clip menus_mc.

To obtain the current highest occupied depth, subtract 1 from the value returned by getNextHighestDepth(), as shown in the next section (see Determining the instance at a particular depth).