490
Animation, Filters, and Drawings
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
event handler, or you can use the
setInterval()
function to
call a function at periodic intervals. If you use the Tween class, you have another option that
lets you modify a movie clip’s
_x
and
_y
properties. You can also add the previously described
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
ball_mc
movie clip on the Stage along the
x
-axis (left to right). The movie clip animates from
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
import
statement. This lets you import the Tween class and easing methods rather
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);
Содержание 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...