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
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.
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();
}
TweenLite.to(mc, 2, {frame:1});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With