Bring to Front Function

This one has been covered a million times on other sites but I thought I’d include it here anyway.

To move a MovieClip or other DisplayObject to the front of the stack, you can use the following function:

public function front(asset:DisplayObject):void
    asset.parent.setChildIndex(asset,asset.parent.numChildren - 1);

// usage:

DisplayObject is used since anything that would be added to the display list (added to the stage) is a DisplayObject at its core. I’ve seen this function all over the web in different forms; quite often they only accept MovieClips or even use the * wildcard. This function will universally work with MovieClips, Textfields or any other display object you want to throw at it.

Leave a Reply