MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 495

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

To create an animation that continues endlessly:
1.
Create a new Flash document called yoyo.fla.
2.
Open the Actions panel and enter the following ActionScript on Frame 1 of the Timeline:
import mx.transitions.Tween;
import mx.transitions.easing.*;
this.createEmptyMovieClip("box_mc", this.getNextHighestDepth());
with (box_mc) {
beginFill(0xFF0000, 60);
moveTo(0, 0);
lineTo(20, 0);
lineTo(20, Stage.height);
lineTo(0, Stage.height);
lineTo(0, 0);
endFill();
}
The first section code begins by importing the Tween class, as well as each class in the
easing package. The next section of code creates a new movie clip with an instance name
of
and draws a rectangle 20 pixels wide and the same height as the Stage.
box_mc
3.
Add the following ActionScript after the code created in the previous step:
var box_tween:Tween = new Tween(box_mc, "_x", Regular.easeInOut, 0,
Stage.width, 3, true);
box_tween.onMotionFinished = function() {
box_tween.yoyo();
};
This code creates a new tween to animate the
x-axis over 3 seconds.
4.
Select Control > Test Movie to test the animation.
The box animates from left to right and back. If the animation isn't smooth, you might
want to increase the document's frame rate from 12 fps to 24 fps.
As the box approaches the right edge of the Stage, it animates outside the boundaries of
the Stage. While this might not seem significant, you might not want the rectangle to
disappear from view off the side of the Stage and then reappear a second later and animate
in the other direction.
To make adjustments, animate the rectangle from 0 pixels to the width of the Stage minus
the width of the
box_mc
5.
To stop the rectangle from disappearing, revise the corresponding lines of code from step 3
to match the following code:
var box_tween:Tween = new Tween(box_mc, "_x", Regular.easeInOut, 0,
(Stage.width - box_mc._width), 3, true);
box_mc
movie clip.
About the Tween and TransitionManager classes
movie clip across the Stage along the
495

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

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?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents