About the Tween and TransitionManager classes 493
To trigger code when an animation is completed:
1. Create a new document, and call it triggerTween.fla.
2. Create a movie clip on the Stage.
3. Select the movie clip instance and type ball_mc into the Instance Name text box in the
Property inspector.
4. Select Frame 1 of the Timeline and add the following code in the Actions panel:
import mx.transitions.Tween;
import mx.transitions.easing.*;
var tween_handler:Object = new Tween(ball_mc, "_alpha", Strong.easeIn,
100, 0, 3, true);
tween_handler.onMotionFinished = function() {
trace("onMotionFinished triggered");
};
If you test this ActionScript in your FLA file, you see the message “onMotionFinished
triggered” appear in the Output panel after
ball_mc finishes fading on the Stage.
5. Select Control > Test Movie to see the animation.
Wait for a moment, and then the instance fades out. When it finishes tweening, you see
the message appear in the Output panel.
For more information on functions, see Chapter 7, “Classes.”
About continuing animations using the continueTo() method
“Using the Tween class” on page 490 demonstrates how to use the Tween class in your
applications. However, if you want to move the ball after the initial animation is complete,
there are at least two ways you can do it. One solution is to reanimate the ball by using the
onMotionFinished event handler. However, the Tween class offers a simpler solution, the
continueTo() method. The continueTo() method instructs the tweened animation to
continue from its current value to a new value, as the following ActionScript shows:
import mx.transitions.Tween;
import mx.transitions.easing.*;
var ball_tween:Object = new Tween(ball_mc, "_x", Regular.easeIn, 0, 300, 3,
true);
ball_tween.onMotionFinished = function() {
ball_tween.continueTo(0, 3);
};