Skip to main content
Known Participant
March 16, 2011
Answered

AS3 on CS3: Does Flash recognize an event when a Tween ends?

  • March 16, 2011
  • 2 replies
  • 719 views

I have a programmatic tween (fl.transitions.Tween) on a MovieClip and want to apply a ColorTransform on it when it ends. Basically, the Tween scales an item down to its original size, and I want to know when the scaleX is back to 1, and then trigger the application of a ColorTransform. Is there a way to do that or must I use a timer in conjunction with the Tween?

This topic has been closed for replies.
Correct answer

Do yourself a favor and never use the built in tween classes again. They suck. Use a good tweening engine: www.greensock.com

With TweenLite or TweenMax - you just do like:

TweenLite.to(myClip, 2, {x:300, onComplete:someFunction});

and someFunction will be called when the tween finishes. TweenLite/Max is miles faster and more effiicient (and actually works) than the Adobe tween classes.

2 replies

Correct answer
March 16, 2011

Do yourself a favor and never use the built in tween classes again. They suck. Use a good tweening engine: www.greensock.com

With TweenLite or TweenMax - you just do like:

TweenLite.to(myClip, 2, {x:300, onComplete:someFunction});

and someFunction will be called when the tween finishes. TweenLite/Max is miles faster and more effiicient (and actually works) than the Adobe tween classes.

Kenneth Kawamoto
Community Expert
Community Expert
March 16, 2011

There is fl.transitions.TweenEvent.MOTION_FINISH event for it

ankhcommAuthor
Known Participant
March 16, 2011

Ok, that's great!

I just need help with using it...

I have the following function:

function scalerMinus(mVictim) {

     var xScale:Tween = new Tween(mVictim, "scaleX", Strong.easeInOut, 1.4, 1, 0.5, true);

     var yScale:Tween = new Tween(mVictim, "scaleY", Strong.easeInOut, 1.4, 1, 0.5, true);

     bSpotLight = false;

     sClipSpotLighted = "";

}

From what I understand I need to return when the TweenEvent.MOTION_FINISH happens. I added return xScale.TweenEvent.MOTION_FINISH at the end and that didn't work. I would need to return that MOTION_FINISH event to use it on a function triggered by a MouseEvent.ROLL_OUT:

function outMunicipality(mouseEvent:MouseEvent):void {

     if (mouseEvent.target.scaleX > 1) {

     mouseEvent.target.transform.colorTransform = new ColorTransform(1, 1, 1, 1);

     scalerMinus(mouseEvent.target);

     }

}

Sorry to ask so much, but this is my first AS3 project after doing everything I could to hold on to AS2 and I'm still going through the "I don't get AS3" phase :/

Kenneth Kawamoto
Community Expert
Community Expert
March 16, 2011

You have to add EventListener to the Tween to listen to the MOTION_FINISH event, for example:

var xScale:Tween = new Tween(mVictim, "scaleX", Strong.easeInOut, 1.4, 1, 0.5, true);

xScale.addEventListener(TweenEvent.MOTION_FINISH, scaleXMotionFinish, false, 0, true);

// function called when Tween finishes
function scaleXMotionFinish(e:TweenEvent):void {
            trace("Tween completed");
}

However I notice you're tweening more than one properties (scaleX and scaleY) simultaneously and believe or not that's more than what Flash Tween can handle As others say, use TweenMax family of Tweens and onComplete built-in property.