actionscript-3flashactionscriptmovieclip

Playing reverse of a MovieClip using ActionScript 3.0


I have made an animation in Adobe Animate. I want it to be played in reverse. I tried reversing frames but it kinda messes up my animation. So I decided to write a code for it instead.

I tried referring to this post for the code: Flash - Play movie clip in reverse?

This makes my animation play reverse whenever my mouse is not on the MovieClip. I am not that well versed with the coding to modify the code to make the animation appear and loop reverse even without hovering the mouse out.

This is the code:

mc.stop();
mc.addEventListener(MouseEvent.MOUSE_OVER,mover);
mc.addEventListener(MouseEvent.MOUSE_OUT,mout);

function mover(e:MouseEvent):void {
    stopPlayReverse();
    mc.play();
}

function mout(e:MouseEvent):void {
    this.addEventListener(Event.ENTER_FRAME, playReverse, false, 0, true);
}

function playReverse(e:Event):void {
    if (mc.currentFrame == 1) {
        stopPlayReverse();
    } else {
        mc.prevFrame();
    }
}

function stopPlayReverse():void {
    if (this.hasEventListener(Event.ENTER_FRAME)) {
        this.removeEventListener(Event.ENTER_FRAME, playReverse);
    }
}

I want the mout to work on Stage directly and loop, instead of stopping. How do I go about that?


Solution

  • I first got the mc to come to last frame first: mc.gotoAndStop("Last");

    Then added:

    stage.addEventListener(Event.ENTER_FRAME,mout); 
    

    And removed:

    mc.addEventListener(MouseEvent.MOUSE_OVER,mover); 
    mc.addEventListener(MouseEvent.MOUSE_OUT,mout);