2012-11-29 18 views
3

我在圖書館裏有幾個動畫片段,我想製作將它們加載到舞臺上的功能。我的問題是我找不到爲每個MovieClip製作單獨的函數的不同解決方案。我正在尋找類似的東西:如何從庫中動態添加對象?

function addAnyClip(name){ 
    //create new object 'name' 
    stage.addChild(chosenObject); 
    rest of code 
} 

,因爲它是優於:

function addClip1(){ 
    var mc1:Clip1 = new Clip1; 
    stage.addChild(mc1); 
    ///rest of code 
} 

function addClip2(){ 
    var mc1:Clip2 = new Clip2; 
    stage.addChild(mc2); 
    ///rest of code 
} 

function addClip3(){ 
    var mc1:Clip3 = new Clip3; 
    stage.addChild(mc3); 
    ///rest of code 
} 
... 

回答

1

這將鞏固你在上面顯示的內容:

function addChildOfType(type:Class):void{ 
    var mc:type = new type(); 
    stage.addChild(mc); 
} 

使用這個只要致電:

addChildOfType(Clip1); 
addChildOfType(Clip2); 
addChildOfType(Clip3); 

編輯:

如果您的圖書館是一個外部加載瑞士法郎,然後@M。 Laing在如何獲得它們方面是正確的。如果你的庫是你的閃存庫在同一個Flash文件中,那麼這個答案將解決你的問題。

+0

非常感謝你:) –

+0

歡迎你!快樂的編碼..哦,並且將這個答案標記爲你想要的答案,如果你願意的話! –