Reputation: 205
i have a bunch of movieclips on the stage and some are nested into others, i would like to have 1 of them to be put on top of everything else on the stage when i start dragging it. Anyone know how to get a nested movieclip on top of parents etc?
Upvotes: 0
Views: 9836
Reputation: 1457
Suppose, Container is your parent movieClip and it has many children then Now your target and currentTarget property depends on which object the listener is attached and how much you have nested your movieclips. in my case the Container is your parent movieClip having two or more children.
Container.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
public function pickUp(param1:MouseEvent) : void
{
var objectToDrag = param1.target;
Container.setChildIndex(param1.target,Container.numChildren-1);
objectToDrag.startDrag(true);
}
Upvotes: 0
Reputation: 3548
top of everything else on stage:
stage.addChild(target);
warning from AS3 doc :
The command stage.addChild() can cause problems with a published SWF file, including security problems and conflicts with other loaded SWF files. There is only one Stage within a Flash runtime instance, no matter how many SWF files you load into the runtime. So, generally, objects should not be added to the Stage, directly, at all. The only object the Stage should contain is the root object. Create a DisplayObjectContainer to contain all of the items on the display list. Then, if necessary, add that DisplayObjectContainer instance to the Stage.
Upvotes: 4
Reputation: 9572
You could have a top layer & a bottom layer , whenever you want to add a child on top of everything else, simply add the child to the top layer. This way you don't need to figure what the parent position is , just keep this layer on top for that specific purpose.
var topLayer:Sprite = new Sprite(); var bottomLayer:Sprite = new Sprite(); var childMc:MovieClip; // the mc you want to have on top //somewhere in your code... childMc.addEventListener(MouseEvent.MOUSE_DOWN , childMcMouseDownListener ); addChild( bottomLayer ); addChild( topLayer ); //add everything to the bottom layer //leave the topLayer empty until you add the child mc //add the following code in your MouseDown Listener function childMcMouseDownListener(event:MouseEvent ):void { topLayer.addChild( event.currentTarget ); }
Upvotes: 4