In the days of AS2, the quick and dirty little line...
mc.swapDepths(mc.parent.getNextHighestDepth());
...would do the trick, and the MC would be on top.
In AS3 there is no "getNextHighestDepth" function. Instead, there is a display stack with no missing slots.
Thus, this is the easiest way to set a MovieClip (or Sprite or DisplayObject, for that matter) to the foremost depth of it's parent container:
public function bringMCToFront($mc:MovieClip){
$mc.parent.setChildIndex($mc, $mc.parent.numChildren-1);
}
or, as a dirty 1 liner:
anyMC.parent.setChildIndex(anyMC, anyMC.parent.numChildren-1);
* remember this only sets $mc to the highest depth within it's parent MC. If the parent MC is beneath other MC's in the same level, the parent will need to have it's depth set as well. Same for the parent's parent, and so on...
Cheers.
Posted on
Tue, September 8, 2009
by Sean P
filed under
-
Flash,
-
AS3,
-
Flex,
-
AS2,
-
Migrating,
-
Porting,
-
Depth,
-
getNextHighestDepth,
-
MovieClip,
-
Sprite,
-
DisplayObject,