2010-10-17 50 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); 
}