Search code examples
actionscript-3animationsequencetween

Animation Sequence with as3


I am stuck at a point, where i want to do a sequence of animation being performed in Flash AS3. I am able to animate my movieclips with the TweenClass, but not able to make them play after one another in a sequence.

I want to make the closeTween to play after the evntInTween has completed playing.

The code which I am using is:

import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;





BtnEvent.buttonMode = true;
BtnEvent.addEventListener(MouseEvent.ROLL_OVER, EventOver);
BtnEvent.addEventListener(MouseEvent.ROLL_OUT, EventOut);
BtnEvent.addEventListener(MouseEvent.CLICK, EventClick);


 function EventOver(event:MouseEvent) {
    event.target.gotoAndPlay(2);
}

 function EventOut(event:MouseEvent) {
    event.target.gotoAndPlay(11);
}


 function EventClick(event:MouseEvent) {
  var evntInTween:Tween = new Tween(eventzmov, "y", Strong.easeOut, 463.75, 1794.6, 3, true);


  var closetween:Tween = new Tween(closeevent, "alpha", Strong.easeOut, 0, 1, 3, true);



}

Solution

  • I think you should nest tweens, so that the second tween is created only after the first one stops playing - it sends fl.transitions.TweenEvent.MOTION_FINISH event after it ends, so you assign a listener to your button to listen to it, don't forget to drop once it will no longer be needed.

    function EventClick(event:MouseEvent) {
        var evntInTween:Tween = new Tween(eventzmov, "y", Strong.easeOut, 463.75, 1794.6, 3, true);
        event.target.addEventListener(TweenEvent.MOTION_FINISH,startSecondTween);
        evntInTween.start();
    }
    function startSecondTween(e:TweenEvent):void {
        var closetween:Tween = new Tween(closeevent, "alpha", Strong.easeOut, 0, 1, 3, true);
        event.target.removeEventListener(TweenEvent.MOTION_FINISH,startSecondTween);
        closetween.start();
    }
    

    }