AS2 Tween Functions
In ActionScript 2.0, often referred to as AS2, developers can create complex animated effects for Flash files. Using the Tween and TransitionManager classes of the ActionScript 2.0 language, developers can define Tweening effects to animate changes in object appearance. The Flash interface allows developers to implement various standard Tween effects, but to define custom effects, some ActionScript code is necessary.
-
Classes
-
The main ActionScript 2.0 classes required to access Tween functions are the Tween class and the TransitionManager class. Flash documents can import certain resources before their code makes use of them, as follows:
import mx.transitions.Tween;
import mx.transitions.easing.*;This provides the document with access to the Tween class together with easing functions, both of which are involved in creating animated transition effects using ActionScript 2.0 code. Once these classes are present, the document can create instances of the Tween class, as well as accessing standard easing functions to apply to the resulting Tween effects.
Creating Tweens
-
To implement an animated Tween in a Flash document, ActionScript code must instantiate the Tween class. Developers can create a Tween object explicitly for later use. For example:
new Tween(myclip_mc, "_y", Elastic.easeIn, 500, 100, 10, true);
This code specifies a Movie Clip symbol to apply the Tween to. The parameters indicate various aspects of the Tween, with the "y" axis indicated as the object property to apply the Tween to, the easing property indicated as easing in, the starting and ending dimensions of the Tween property, the duration to make the Tween last and a true or false value indicating whether the duration should be measured in seconds or frames. In this case the Tween shrinks the symbol on its "y" axis, from 500 to 100 pixels, lasting 10 seconds.
-
Tween Methods
-
The ActionScript 2.0 Tween class provides a range of methods developers can choose to call on object instances of the class. These methods instruct Flash to move to particular points within the animation sequence defined by the Tween. For example, the "fforward" method moves immediately to the end of the animation. Other Tween methods move to the next and previous frames, rewind, start and stop the animation.
Events
-
Developers can add event handler functions to their Flash Tween processing. This allows a Flash document, for example, to specify what should happen when a Tween animation completes. The event handler functions for the Tween class include "onMotionStarted" for when the animation begins, "onMotionStopped" for when it stops, "onMotionFinished" for when the Tween finishes, "onMotionResumed" for when it starts after stopping and "onMotionChanged" for any change in the property of the object that is subject to the Tween.
-
References
- Adobe: Learning ActionScript 2.0 in Adobe Flash - About the Tween and TransitionManager Classes
- Adobe: Learning ActionScript 2.0 in Adobe Flash - About the Tween Class
- Adobe: ActionScript 2.0 Components Language Reference - Tween Class
- Adobe: Learning ActionScript 2.0 in Adobe Flash - Using the Tween Class
Resources
- Photo Credit BananaStock/BananaStock/Getty Images