2013-05-01 27 views
0

我在時間線上有大約7翻領的影片剪輯,我希望標籤的每個部分重複2次,直到時間軸結束,並且在影片剪輯時間軸上根本沒有任何代碼。我試圖用if語句來完成它,但它只是沒有解決問題,有沒有辦法使用for循環來做到這一點?as3如何重複部分movieclip時間線從標籤到標籤的次數

var repeat:Number = 2; 
var repeating:Number = 1; 
var mcFramelabel = 'label1'; 
var labelNum:Number = 1; 
mc1.addEventListener(Event.ENTER_FRAME, repeatLabel); 
function repeatLabel(e:Event):void 
{ 
if (mc1.currentLabel == mcFrameLabel) 
{ 
    repeatIt(); 
} 
} 

function repeatIt(){ 
var labelNumCont:Number; 
if (repeating < repeat && mcFramelabel == 'label1'){ 
    repeating++; 
    mc1.gotoAndPlay(2); 
}else if (repeating < repeat && mcFramelabe != 'label1'){ 
    repeating++; 
    labelNum++; 
    labelNumCont = labelNum - 1; 
    mcframelabel = 'label'+labelNumCont; 
    mc1.gotoAndPlay(mcframelabel) 
}else if (repeating == repeat){ 
    repeating = 1; 
    labelNum++ 
    mcFramelabel = 'label'+labelnum; 
    mc1.gotoAndplay(mcfameLable); 
} 
} 

回答

0

UPDATE

如果你加載SWF文件到您的影片剪輯,並希望從SWF使用的標籤,請確保您引用SWF的時間軸上的標籤,而不是容器影片剪輯的標籤。也就是說,如果您想控制動畫片段之外的播放(除了需要不同的觸發事件),基本實現保持不變。

mc1.addEventListener(Event.ENTER_FRAME, tick); 
var count:Object = {}; 

function tick(e:Event):void { 
    if (mc1.currentFrameLabel != null) { // If the playhead is resting on a frame with a label... 
     for each (var label in mc1.currentLabels) { // loop through the mc's list of labels. 
      if (count.hasOwnProperty(label) == false) { // if we don't have a value for this label 
       count[label] = 1; // store it 
       break; // break the loop, and allow the playhead to continue. 
      } else if (count[label] < 2) { // If we haven't met our desired count 
       count[label]++; // increment 
       mc1.gotoAndPlay(label); // and go back to that label 
       break 
      } 
     } 
    } 
} 

我還沒有測試過它,但我認爲應該這樣做。感興趣的是,您可能需要查看MovieClip.currentLabels


請注意,所有相關代碼在每次幀更新期間都會完全運行。一個循環會在它被調用的毫秒內執行所有代碼,所以在這種情況下這不是你想要的。

您可以嘗試存儲每個標籤播放的計數並在每個標籤之前檢查該計數。例如,假設您有以下時間表設置:

label1     check() label2 
    |   |   |   | 
    0   1   2   3 

您的代碼應該是這樣的......

var count:Object = {}; 
function check():void { 
    // Make sure this label exists in our count 
    if (count.hasOwnProperty(mc1.currentLabel) == false) { 
     count[mc1.currentLabel] = 1; 
     mc1.gotoAndPlay(mc1.currentLabel); 
    } 
    // If the label is already present in the count, then this will be our 
    // second playthru, and we can let the playhead continue to the next label. 
} 

另外,如果你想重播框架10倍,你可以增加它這樣...

var count:Object = {}; 
var repeat:int = 10; 

function check():void { 
    // Make sure this label exists in our count 
    if (count.hasOwnProperty(mc1.currentLabel) == false) { 
     count[mc1.currentLabel] = 1; 
    } else { // increment the count 
     count[mc1.currentLabel]++; 
    } 

    // If we haven't reached our goal, go back to the label. 
    if (count[mc1.currentLabel] != repeat) { 
     mc1.gotoAndPlay(mc1.currentLabel); 
    } 
} 
+0

謝謝,事情是我沒有在正在加載的影片剪輯代碼,所有的代碼是在一個包中,所以我將不得不使用一個事件來知道什麼幀電影在。 movieclip是一個容器,並且swf被加載到它中,當一個swf完成時,另一個被加載到相同的movieclip中。我的裝載機工作良好。但重複標籤之間的幀沒有在加載的瑞士法郎代碼是我想要做的。 – user2338684 2013-05-01 20:05:40

+0

非常感謝 – user2338684 2013-05-02 19:25:11