开发者

getting movieclip on top of everything else

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 开发者_Go百科of everything else on the stage when i start dragging it. Anyone know how to get a nested movieclip on top of parents etc?


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 );
}


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.


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜