Flash CS4 ActionScript 3.0 Tutorial
How to Vary the Speed and Duration when Applying an ActionScript Tween in Flash
Easing is used with transitions and tweening. For more information, see topics, Blinds Transition, Fade Transition, Fly Transition, Iris Transition, Photo Transition, Pixel Dissolve Transition, Rotate Transition, Squeeze Transition, Wipe Transition, Zoom Transition, and Tweening Object Properties. There are several easing choices (i.e., Back, Bounce, etc) and multiple ways to apply the ease (i.e., easeIn, easeOut, or easeInOut).
In this example we will demo the Back ease on the rotation property. You can change the rotation parameter to any other object property (i.e., alpha, height, rotationX, rotationY, rotationZ, scaleX, scaleY, width, x or y). To make things even more exciting, consider duplicating your tween and assigning the new tween a new variable name. In the second tween, change the property so now the object tweens two properties at the same time.
Movie Symbol with instance name blueBar_mc
Add a Movie Symbol to the stage and select the symbol with the Selection tool (v key). For info on creating a Movie Symbol, see topic, Movie Symbol Basics.
Open the Properties panel (Cmd/F3 (PC-Ctrl/F3)) and type in the name blueBar_mc for the Instance Name.
Add a new layer called Actions.
Option double-click (PC - Alt double-click) the keyframe in the Actions layer to open the ActionScript panel.
Copy/Paste the following code to the ActionScript panel.
var adjRotation:Tween = new Tween (blueBar_mc, "rotation", Back.easeIn, 15, 180, 2, true);
//Tween Options: instance name, "object property", ease type, start value, end value, duration, true = seconds false = frames;
Test your movie by pressing Cmd/Return (PC - Ctrl/Enter). The object starts with a 15 degree rotation. It backs up slightly then it rotates 180 degrees in a clockwise direction. The backing motion is caused by the Back setting.
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 blueBar_mc and targets the object's rotation property. The ease is set to Back and it happens in the beginning.
The object is rotated 15 degrees clockwise before the the tween begins. It then backs up and makes it's 180 degree rotation. It occurs over 2 seconds. By setting the last parameter to true, the values are in seconds, not frames.
More Ease Options
You can substitute easeIn (beginning) with easeOut (end) or easeInOut (beginning and end). You can always replace Back with None to cancel the Back feature.
Tweens and Animated Movie Symbols
Consider using an animated Movie Symbol in your Tweens. The animation plays while the Tween creates additional movement.
Stopping and Starting a Tween
At times you may want to stop, start or start your Tween back at the beginning. Since you assigned a variable to the Tween, you can supply the variable with specific instructions. For instance, the following lines of code control the Tween in our example.
//stops the tween
//resumes playing the tween
//starts the tween at the beginning