For example, imagine that you want to move a movie clip across the Stage. You can add
keyframes to a timeline and insert a motion or shape tween between them, you can write
some code in an
onEnterFrame
call a function at periodic intervals. If you use the Tween class, you have another option that
lets you modify a movie clip's
easing methods. To take advantage of the Tween class, you can use the following ActionScript:
new mx.transitions.Tween(ball_mc, "_x",
mx.transitions.easing.Elastic.easeOut, 0, 300, 3, true);
This ActionScript snippet creates a new instance of the Tween class, which animates the
movie clip on the Stage along the x-axis (left to right). The movie clip animates from
ball_mc
0 pixels to 300 pixels in three seconds, and the ActionScript applies an elastic easing method.
This means that the ball extends past 300 pixels on the x-axis before using a fluid motion
effect to animating back.
You can find a sample source file that adds scripted animation using these classes. Find
tweenProgress.fla in the Samples folder on your hard disk.
In Windows, browse to boot drive\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\Tween ProgressBar.
On the Macintosh, browse to Macintosh HD/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/Tween ProgressBar.
Using the Tween class
If you use the Tween class in more than one place in your Flash document, you might opt to
use an
statement. This lets you import the Tween class and easing methods rather
import
than give the fully qualified class names each time you use them, as the following
procedure shows.
To import and use the Tween class:
1.
Create a new document and call it easeTween.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.*;
new Tween(ball_mc, "_x", Elastic.easeOut, Stage.width, 0, 3, true);
490
Animation, Filters, and Drawings
event handler, or you can use the
and
properties. You can also add the previously described
_x
_y
function to
setInterval()
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?
Questions and answers