Tweening Object Properties

Tweening Object Properties

Flash CS4 ActionScript 3.0 Tutorial


How to Vary the Speed and Duration when Applying an Object Property with Flash ActionScript



The rotation property determines the object's rotation about its registration point. The values are set in degrees and measured in a clockwise direction. Using this tween you can control the object rotation speed as it enters the stage.For more information about setting and moving the registration point, see topic, Setting and Moving Object Registration Point.

Tutorial Elements

Movie Symbol with instance name redShape_mc


Step One

Add a Movie Symbol to the stage and select the symbol with the Move tool.

Step Two

Select the object and open the Properties panel (Cmd/F3 (PC-Ctrl/F3)). Type in the name redShape_mc for the Instance Name.

Step Three

Add a new layer called Actions.

Step Four

Option double-click (PC - Alt double-click) the keyframe in the Actions layer to open the ActionScript panel.

Step Five

Copy/Paste the following code to the ActionScript panel.

import fl.transitions.Tween;

import fl.transitions.easing.*;

var AdjRotation:Tween = new Tween (redShape_mc, "rotation", Strong.easeIn, 30, 150, 1.8, true);

//Tween Options: instance name, "object property", ease type, start value, end value, duration, true = seconds false = frames;

Step Six

Test your movie by pressing Cmd/Return (PC - Ctrl/Enter). The object is placed on the stage with a 30 degree rotation, it then rotates 120 degrees in a clockwise direction.

Dissecting the Code

The first two lines import the Tween Class and easing package into your document. The var line establishes a new Tween. It affects the redShape_mc and targets the object's rotation property. The ease is set to Strong and happens in the beginning.

The object is rotated 30 degrees clockwise before the the tween begins. This is the object's starting value. The total rotation is 120 degrees (150 - 30 = 120). The 150 value is the object's final rotation value. It occurs over 1.8 seconds. By setting the last parameter to true, the values are in seconds, not frames.

Tons of Options

In addition to rotation, you can assign a tween to alpha, scaleX, scaleY, width, height, and the object's x and y position.

Strong can also be substituted with Back, Bounce, Elastic, None, or Regular. For more information, see topics, Back Easing, Bounce Easing, Elastic Easing, Regular Easing, or Strong Easing.

The rotation values and duration can be altered. If you change the final value to false, the time is measured in frames. In other words, if your animation was running at 18 fps and you wanted it to last for two seconds, the last two values would read 36, false. career skills