Tweening
The Tween Class inside flash lets us create simple animations easily in ActionScript by specifying the starting and ending points of an object animation positions. It can actually be used to tween any property of any object.
By the term tween we mean here the gradual increase or decrease of the value of a property which can bring about an animation. This could be the increase of transparency, the decrease in width, or the movement from left to right of any object.
The Tween Class is not included by default in a Flash movie and must be imported before it can be used, Adobe did this to ensure to help making SWF files smaller so that the Class is included only in movies that require it. To import this class you must use the import directive at the beginning before you start your actual code. Here is the code you need:
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
The Tween Class must be used through an instance of it (using a variable).
When instantiating the Tween Class you must provide the parameters required by the TWeen Class.
|
var |
myTween |
: |
Tween |
= |
new Tween |
( |
object |
, |
"property |
, |
EasingType |
, |
begin |
, |
end |
, |
duration |
, |
time |
) |
; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var |
name |
: |
data type |
= |
initial value |
( |
1 |
, |
2 |
, |
3 |
, |
4 |
, |
5 |
, |
6 |
, |
Boolean |
) |
; |
var rectTween:Tween =new Tween ( (rectangle_mc, "x", Strong.easeOut, 0 , 300, 3, true)
Explanation of the parameters a Tween instance uses
1. object - This is the instance name of the object which will be animated. Example: my_box
2. property - This is the name of the property which will be animated, it must be specified as a string (between quotation marks). Example: "alpha", "scaleX", "scaleY", "x", "y".
3. easingType - The easing type will determine how the tween animation will flow. You need to use first the EaseClass or type of ease, then within the easing class specify the EasingMethod. You write it with dot syntax like that: EaseClass . Ease Method
Examples: Strong.EaseIn, Elastic.EaseOut, Back.EaseInOut.
4. begin - This is the position from which the animation will start, it must be specified as a number.
5. end - This is the position at which the animation will stop, it must be specified at as a number.
6. duration - This is the period for which the animation will run, it is structured as a Boolean. The default unit for it is frames, however, the unit can be set in seconds if you set the next parameter as true.
Ease Methods
Each of the previous functions must be then be configured using one of the easing methods to determine at which part of the tween it shall apply the effect, i.e. at the start of it, the end of it, both, or none:
easeIn: The tween effect is applied to the start of the animation.
easeOut: The tween effect is applied to the end of the animation.
easeInOut: the tween effect is applied to the start and end of the animation.
easeNone: no tweening effect is applied, to be used with the None tween function.