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.ad
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();
}
You can do it passing the movie clip object to find the correct object to reverse. This manner helps you to use with the child you want. You can get it with:
fMoveBack(this.getChildByName("my_clip"));
function fMoveBack(my_clip:MovieClip):void {
this.addEventListener(Event.ENTER_FRAME, playReverse(my_clip));
}
function playReverse(mc:MovieClip):Function {
return function playReverse(e:Event):void {
if (mc.currentFrame == 1) {
stopPlayReverse(mc);
} else {
mc.prevFrame();
}
};
}
function stopPlayReverse(mc:MovieClip):void {
if (this.hasEventListener(Event.ENTER_FRAME)) {
this.removeEventListener(Event.ENTER_FRAME, playReverse);
}
}
TweenLite.to(mc, 2, {frame:1});
If your tween is not all that serious you can literally make a whole new set of frames in reverse and just play it from that keyframe.
That's the poor man's reverse tween.
By using a boolean which works as a trigger and Event.ENTER_FRAME
, you can do the following to reverse frames:
//Boolean and Event.ENTER_FRAME
var reversing:Boolean = false;
AddEventListener(Event.ENTER_FRAME, reverse);
function reverse(e:Event){
if(reversing)
{
//mc is displaying previous frame every frame
mc.prevFrame();
//until the currentFrame is 1
if(mc.currentFrame == 1)
reversing = false;
}
}
Your //Play in reverse
would set reversing = true;
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.