循环动画直到按下按钮,但让动画完成

问题描述 投票:0回答:2

我知道我必须做什么,只是不知道怎么做。

我知道我必须(在完成所有动画和诸如此类之后)声明第1帧上的所有变量(在单独的时间线中),例如a = 0; b = 0 ...

然后在循环结束时执行gotoandplay到一个条件(在第120帧,如果a = 0 gotoandplay(100),否则gotoandplay(15)

然后有一个按钮来改变a的值,这样当循环遇到条件时它会转到我想要的任何帧。

有什么指针吗?谢谢

actionscript-3 air flash-cs6 animate-cc
2个回答
0
投票

假设您的按钮的实例名称为btn,并且循环动画的实例名称为mc_loop

你可以这样做:

//listen for the mouse click on your button
btn.addEventListener(MouseEvent.CLICK, buttonClicked, false, 0, true);

//run this function on the click
function buttonClicked(e:Event):void {
    //add a script to the last frame that calls this inline function
    //the addFrameScript method wants a 0 based frame number, so the first frame would be 0,  the last frame would the total frame count less 1
    mc_loop.addFrameScript(mc_loop.totalFrames-1, function(){
        mc_loop.stop(); //stop the clip so it doesn't loop anymore
        mc_loop.addFrameScript(mc_loop.totalFrames-1, null); //remove the frame script so it doesn't run again should mc_loop reach the last frame again
    });
}

使用此代码,假设mc_loop已经在播放/循环,单击btn将在它到达最后一帧时停止它。


0
投票

所以我已经采纳了你的两个建议,并做到了这一点

1个动画,左右一个圆圈,一个按钮从第1-20帧开始,文字说“完成”一个层21

3层:动作按钮层1(动画层)

之后,我在Action框架1上设置了代码

var loop:Boolean =true

在第20帧

if (loop==true){
        gotoAndPlay(2);
}else {
gotoAndStop(21)
}

然后在按钮上,做了

btn.addEventListener(MouseEvent.CLICK, buttonClicked, false, 0, true);
function buttonClicked(e:Event):void {
    loop=false
    }

它奏效了。循环结束,然后它进入第21帧,然后停在那里。

我错过了什么吗?或者这是一个很好的解决方案? (也可以用这个菜单,用case而不是if和整数值跳转到我想要的章节)

© www.soinside.com 2019 - 2024. All rights reserved.