Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flash - Play movie clip in reverse?

I'm trying to get a movie clip to play in reverse when I mouse_out from it (it plays on mouse_over).

My actionscript is as follows:

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

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

function mout(e:MouseEvent):void
{
   //Play in reverse
}

How would I achieve this?

Thanks

like image 400
Probocop Avatar asked Jan 12 '10 14:01

Probocop


3 Answers

The best way would be to use an ENTER_FRAME event listener. Basically this is what you want to do

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

This would play your MovieClip in reverse until it hits frame 1, then it will stop.

like image 111
sberry Avatar answered Oct 31 '22 23:10

sberry


If the motion allows, you can use a Tween (for example if you want to change the alpha, location or scale). On the MouseOut you can call .yoyo() for the Tween, which will play it in reverse.

Something like this:

var tween:Tween;

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

function mover(e:MouseEvent):void
{
    tween = new Tween(obj, "alpha", None.easeNone, 1, 0, 1, true);
}

function mout(e:MouseEvent):void
{
   tween.yoyo();
}
like image 5
Pbirkoff Avatar answered Nov 01 '22 00:11

Pbirkoff


TweenLite.to(mc, 2, {frame:1});
like image 4
a--m Avatar answered Nov 01 '22 01:11

a--m