尝试在按住按钮的同时让动画向后播放,这很好,但是当它到达第一帧时它会停止并且不会循环回到动画的最后一帧 - 如何一个完成这个?看起来我需要以某种方式打破一个帧的事件,然后再开始听......
backward_btn.addEventListener(MouseEvent.MOUSE_DOWN, setDownTrue);
backward_btn.addEventListener(MouseEvent.MOUSE_UP, setDownFalse);
addEventListener(Event.ENTER_FRAME, checkDown);
var isDown:Boolean = false;
function setDownTrue(e:MouseEvent){
isDown = true;
}
function setDownFalse(e:MouseEvent){
isDown = false;
}
function checkDown(e:Event){
if(isDown == true){
prevFrame();
if(currentFrame == 1){
gotoAndStop(120); //120 is the last frame of the animation
isDown = false;
}
}
}
谢谢!
答案 0 :(得分:1)
ENTER_FRAME
事件不是您的问题,它会继续触发。但是,isDown
在最后一帧变为false。您应该在isDown = false;
行之后将isDown = true;
更改为gotoAndStop
,以便不断循环播放。
答案 1 :(得分:1)
我实际上只是帮助了一位同事:
myMovieClip //your instance on the stage
假设你想让你的movieclip在点击时向后播放:
myMovieClip.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void
{
addEventListener(Event.ENTER_FRAME, playBackwards);
}
function playBackwards(e:Event):void
{
var frame:int = myMovieClip.currentFrame -1; //get frame before current;
myMovieClip.gotoAndStop(frame); // go to that frame
if(frame == 1) removeEventListener(Event.ENTER_FRAME, playBackwards); //if the frame is the first frame then remove the enterframe event
}
答案 2 :(得分:0)
为自己省点麻烦并使用totalFrames
:
if(currentFrame == 1)
gotoAndStop(totalFrames);
else prevFrame();