动画完成AS3后,在Movieclip中继续

时间:2014-02-07 22:53:36

标签: actionscript-3 flash button transition movieclip

我的舞台上有一个Movieclip,其中包含两个按钮:Back和Next。同样在时间轴上,我有另一个包含动画的Movieclip。单击下一个按钮后,我想让动画过渡到下一个动画而不跳跃。那么,有没有什么方法可以让我听完动画,这样我就可以无缝地进行过渡了?

以下是我的“下一步”和“后退”按钮的代码(这是影片剪辑按钮的原因,这就是为什么有所有额外的代码),这些代码在目前的帧之间切换:

//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();
}

谢谢,感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

如果您的动画有时间轴,请在动画movieClip的最后一帧中调用 animationComplete 函数。此函数与上面发布的代码的范围相同,因此您必须能够从动画片段中正确地路径化它。例如,如果代码是动画movieClip(mc的父级)之外的一级,则可以调用this.parent.animationComplete(),它将包含动画完成时要执行的代码。

答案 1 :(得分: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

你已经弄明白了,所以要完成可以在MovieClip的最后一帧的代码中添加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();
    }
}
相关问题