
Beginning ActionScript 2.0 2006
.pdf





17
Automated Transitions
So far, you have been creating animations at a low level, where you implement all of the animation code yourself. This certainly yields maximum control over animation and interactivity; however, Flash also gives you a more automated way of animating in the form of the Tween class. This class allows you to create transitions with any movie clip property.
The Tween Class
The Tween class was actually available in Flash MX 2004; however, it was not immediately documented. This is too bad, because it is an immensely useful class. The idea behind this class is that you can take any numeric movie clip property and transition the property values from one number to another number. The general form for the Tween class is as follows:
import mx.transitions.Tween;
var myTween:Tween = new Tween(clipHandle:Object, propertyName:String, ;
easingFunction:Function, startValue:Number, stopValue:Number, ; duration:Number, useSeconds:Boolean);
The first parameter, clipHandle, holds the movie clip being targeted for animation. It can actually hold a handle to any object, such as a component or an instance of a custom class. The second parameter, propertyName, is a string representing which property to change. Some examples are _x, _alpha, and _rotation. The easingFunction parameter takes a handle to a function that calculates how the animation accelerates and decelerates when going from the start to the end values. Each of the six built-in easing classes has four easing methods. Next, startValue and stopValue can be any numerical values. If useSeconds is set to true, then duration sets the number of seconds that the animation will take to complete. If useSeconds is set to false, then the duration value sets the number of frames that the animation will take to complete.
The clipHandle and propertyName parameters can actually be empty if you are not using the tween to directly manipulate a movie clip. If you use the onMotionChanged event, you can still get each tweened value, and you can indirectly animate one or more objects based on that. The next Try It Out exercise shows this in action.



