Bring Display Object to Top

Actionscript:
  1. mc.addEventListener(MouseEvent.ROLL_OVER, onRollOver);
  2. function onRollOver(evt:MouseEvent):void {
  3.   addChild(MovieClip(evt.currentTarget));
  4. }

This one is very simple, but it's important to note that using addChild() on something that is already on the display list simply brings it to the top. Back in AS2 we used to do:

Actionscript:
  1. mc.swapDepths(1000);

This entry was posted in DisplayObject, display list and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. Posted December 21, 2008 at 10:01 am | Permalink

    I saw Lee Brimelow first use this a while back and have been using it ever since. It’s a great little trick.

  2. Posted December 21, 2008 at 10:14 am | Permalink

    Yeah its a good one. When I first started with AS3 I thought that doing this might add the clip a second time… sort of like what duplicateMovieClip used to be.

    Lee Brimelow’s stuff is great. I really like the two pixel bender tutorials.

  3. Posted December 22, 2008 at 2:09 am | Permalink

    Interesting. I usually use this:

    [code]
    public static function moveToTop(obj:Object):void
    {
    obj.parent.setChildIndex(obj as DisplayObject, obj.parent.numChildren - 1);
    }
    [/code]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*