2012-01-27 72 views
0

我創建了一個有120幀的動畫片段。當它到達特定幀時停止動畫片段

現在我已經在舞臺上使用了這個動畫片段的多個實例。

我希望每個動畫片段在到達特定幀時停止。 (車架號碼是不同的所有實例)

我嘗試下面的代碼

if (char_1.currentFrame == 36) {char_1.stop();} 

,但它不工作。我試圖跟蹤當前幀,它總是顯示1.

trace(char_1.currentFrame); 

任何解決方案,請?

回答

0

嘗試這樣:

// root 
var allMCs:Dictionary = new Dictionary(); 
allMCs[char_1] = 32; // frame on which to stop char_1 
allMCs[char_2] = 12; // frame on which to stop char_2 
allMCs[char_3] = 47; // frame on which to stop char_3 
// ... add more 

// add ENTER_FRAME listener 
this.addEventListener(Event.ENTER_FRAME, onEnterFrame); 

function onEnterFrame(evt:Event):void 
{ 
    // loop through all MCs and check their frame 
    for (var mc:MovieClip in allMCs) 
    { 
     trace(mc + " frame: " + mc.currentFrame); 
     if (mc.currentFrame == allMCs[mc]) 
     { 
      mc.stop(); 
     } 
    } 
} 

如果痕跡仍然指出了currentFrame是1,請務必在每次使用MC做一個play();