0
votes

Trying to get an animation to play backwards while a button is held down, which works fine, however when it gets to the first frame it just stops and won't loop back around to the last frame of the animation- how might one accomplish this? It seems like I need to break the event for a frame somehow and then start listening again...

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;
        }
    }

}

Thanks!

3
I'll post my animation class i did that plays backwards depanding on the speed you set it (-1 to play backward), if you want. Your code should work, the problem is most likely like you said, doesnt has the time to play its frame to 120 before it gets ask to prevFrame again - Dr.Denis McCracleJizz

3 Answers

1
votes

The ENTER_FRAME event is not your problem, it continues to trigger. However, isDown turns into false on the last frame. You should change isDown = false; to isDown = true; after the gotoAndStop line in order to loop continuously.

1
votes

I actually just helped a co-worker with this:

myMovieClip //your instance on the stage

lets say you want your movieclip to play backwards on click:

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
}
0
votes

Save yourself some trouble and use totalFrames:

if(currentFrame == 1)
    gotoAndStop(totalFrames);

else prevFrame();