2010-10-17 97 views
0

我在舞台上有一堆动画片段,有些嵌入到其他片段中,我想将其中的一个放在舞台上的其他任何东西上面,当我开始拖动它时。任何人都知道如何获得父母等嵌套的动画片段?在其他任何东西上获得动画片段

回答

0

假设容器是您的父级影片剪辑,并且它有许多孩子现在您的目标和currentTarget属性取决于侦听器连接的是哪个对象以及您嵌套了多少影片剪辑。在我的情况下,容器是您的父级影片剪辑有两个或更多的孩子。

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

顶级一切的舞台上:

stage.addChild(target); 

警告从AS3文档:

的stage.addChild()命令可导致与发布的SWF文件 问题包括安全问题以及与其他加载的SWF文件的冲突。在Flash运行时实例中只有一个Stage,没有 是您加载到运行时的SWF文件数量。所以,一般来说, 对象不应直接添加到舞台上。舞台应该包含的唯一 对象是根对象。创建一个 DisplayObjectContainer以包含显示器 列表中的所有项目。然后,如有必要,将该DisplayObjectContainer实例添加到舞台的 。

4

您可以将顶层&作为底层,只要您想在其他任何位置上添加子项,只需将子项添加到顶层即可。这样你就不需要知道父母的位置了,只是为了这个特定的目的而把这个图层放在最前面。

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