2014-02-07 39 views
0

我的舞臺上有一個包含兩個按鈕的Movieclip:Back和Next。另外在時間軸上,我還有另一個包含動畫的Movieclip。點擊下一個按鈕後,我想讓動畫不跳躍地轉換到下​​一個動畫。那麼,我有什麼方法可以聽完動畫的完成,以便我可以無縫地進行轉換?在動畫完成後進入Movieclip AS3

這裏是我的下一步和後退按鈕(這是將影片剪輯按鈕這就是爲什麼有所有的額外代碼)截至目前幀之間剛剛切換代碼:

//NEXT BUTTON 
nextBtn.buttonMode = true; 

nextBtn.addEventListener(MouseEvent.ROLL_OVER, nextBtnOver); 
nextBtn.addEventListener(MouseEvent.ROLL_OUT, nextBtnOut); 
nextBtn.addEventListener(MouseEvent.MOUSE_DOWN, nextBtnDown); 
nextBtn.addEventListener(MouseEvent.MOUSE_UP, nextBtnUp); 

function nextBtnOver(e:MouseEvent):void 
{ 
    nextBtn.gotoAndPlay("over"); 
} 

function nextBtnOut(e:MouseEvent):void 
{ 
nextBtn.gotoAndPlay(9- (nextBtn.currentFrame-1)); 
} 

function nextBtnDown (e:MouseEvent):void 
{ 
nextBtn.gotoAndPlay("down"); 
} 

function nextBtnUp (e:MouseEvent):void 
{ 
    nextBtn.gotoAndPlay(5); 
    MovieClip(root).nextFrame(); 
} 

//BACK BUTTON 
backBtn.buttonMode = true; 

backBtn.addEventListener(MouseEvent.ROLL_OVER, backBtnOver); 
backBtn.addEventListener(MouseEvent.ROLL_OUT, backBtnOut); 
backBtn.addEventListener(MouseEvent.MOUSE_DOWN, backBtnDown); 
backBtn.addEventListener(MouseEvent.MOUSE_UP, backBtnUp); 

function backBtnOver(e:MouseEvent):void 
{ 
    backBtn.gotoAndPlay("over"); 
} 

function backBtnOut(e:MouseEvent):void 
{ 
    backBtn.gotoAndPlay(9- (backBtn.currentFrame-1)); 
} 

function backBtnDown (e:MouseEvent):void 
{ 
    backBtn.gotoAndPlay("down"); 
} 

function backBtnUp (e:MouseEvent):void 
{ 
    backBtn.gotoAndPlay(5); 
    MovieClip(root).prevFrame(); 
} 

感謝,任何幫助非常感謝。

+0

你想要什麼我不明白,你的意思添加輸入框事件,並檢查了MovieClip達到其'currentFrame'? – Cilan

+0

我想讓它在你點擊下一個按鈕時無關緊要,因爲我希望時間軸上的動畫能夠在下一個按鈕的效果完成之前完成,如果這是有意義的。我有一個動畫定時,所以如果它完成它的動畫,它將無縫地轉換,否則它會跳轉 - 這正是我想要避免的。 –

+0

爲什麼不在'nextBtnUp()'中檢查動畫currentFrame。那就是'if(animation.currentFrame == animation.totalFrames)'然後你可以做'nextFrame()'等等 –

回答

0

如果您的動畫有時間限制,請在動畫movieClip的最後一幀中調用animationComplete函數。這個函數的活動範圍與上面的發佈代碼相同,因此您只需要從動畫片段中正確地路徑即可。例如,如果代碼是動畫movieClip(mc的父級)之外的一個級別,那麼可以調用this.parent.animationComplete(),它將包含動畫完成時要執行的代碼。

0

根據您的意見,

I tried this, and it works - except in order for 
it to advance to the next point you have 
to click the next button at exactly the right frame. 
I'd like to make it so you can click it at any point in the Movieclip, and it 
will play the remainder of the Movieclip before proceeding 
to the next frame. Here's my code for what I've added: function 
nextBtnUp(e:MouseEvent):void { 
nextBtn.gotoAndPlay(5); if (MovieClip(root).animationTest.currentFrame == 
MovieClip(root).animationTest.totalFrames) MovieClip(root).nextFrame(); 
} 
Thank you for the help so far 

你擁有了它大部分是想通了,所以要完成可以在您的影片剪輯的最後一幀中的代碼添加stop(),或者你可以這樣做(更復雜的版本):

yourClip.yourFirstClip.addEventListener(Event.ENTER_FRAME, stopAtLastFrame); 
yourClip.yourSecondClip.addEventListener(Event.ENTER_FRAME, stopAtLastFrame); 
function stopAtLastFrame(e:Event):void 
{ 
    if(e.currentTarget.currentFrame === e.currentTarget.totalFrames) 
    //        ^Note that no conversion is being made, so you can have 3 equal signs 
    { 
     e.currentTarget.stop(); 
    } 
} 
+0

好吧,如果我添加一個stop();在最後一幀,動畫停在那裏。我希望動畫不斷循環,直到用戶點擊下一個按鈕,然後纔等待動畫完成,然後才能進入下一個狀態。現在,我只有一個大型動畫片段和一個gotoAndPlay(1);命令在時間線中間,所以它在一半的時間內循環。如果我可以有一個等待動畫完成的命令,然後將用戶發送到gotoAndPlay()命令後面的幀,那將是更可取的。謝謝。 –

+0

@Michael_McAfee請看[Booleans](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Boolean.html) – Cilan