2
votes

Is there a way to send a specific movieClip to the front of all other movieClips on stage?

I know about setChildIndex, but I can't figure out a way to to calculate the top position dynamically.

5

5 Answers

13
votes

You can use setChildIndex() with numChildren.

setChildIndex(childClip, numChildren - 1);
4
votes

You don't need to use setChildIndex. addChild is sending child on the top of all clips. You may be thinking that addChild will double add your MC, but it will not, the second time it will just update it's child index.

0
votes

By default, flash adds the movieclip to the top of the display list, so you can just repeat adding of the child to the container.

stage.addChild(bottom);
stage.addChild(top);
// top is now on bottom.

stage.addChild(bottom);
// bottom is now on top.
0
votes

The movieclip(mc) is added on the canvas,

canvas.setChildIndex(mc, 0);

The canvas is added on the stage,

stage.setChildIndex(canvas, 0);
-1
votes
/* Bring Any Clicked Object to the Front
Clicking on any symbol on the Stage moves it in front of all other instances.
*/

// This code makes all symbol instances on stage clickable by making them listen for the CLICK event.
for (var fl_ChildIndex:int = 0;
    fl_ChildIndex < this.numChildren;
    fl_ChildIndex++)
{
    this.getChildAt(fl_ChildIndex).addEventListener(MouseEvent.CLICK, fl_ClickToBringToFront);
}

// This is the function that moves the clicked object to the front of the display list

function fl_ClickToBringToFront(event:MouseEvent):void
{
    this.addChild(event.currentTarget as DisplayObject);
}

From Adobe Flash Professional Code Snippets.