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:

1
2
3
4
5
6
7
8
public function front(asset:DisplayObject):void
{
    asset.parent.setChildIndex(asset,asset.parent.numChildren - 1);
}

// usage:
front(myMovieClip);
front(someTextField);

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.

Share on FacebookShare on Google+Share on StumbleUponTweet about this on TwitterEmail this to someone

Facebook comments:

Leave a Reply