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);
};
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...