About the Tween class

The Tween class lets you move, resize, and fade movie clips easily on the Stage. The constructor for the mx.transitions.Tween class has the following parameter names and types:

function Tween(obj, prop, func, begin, finish, duration, useSeconds) {
    // code ...
}

obj The movie clip object that the Tween instance targets.

prop A string name of a property in obj to which the values are to be tweened.

func The easing method that calculates an easing effect for the tweened object's property values.

begin A number that indicates the starting value of prop (the target object property to be tweened).

finish A number that indicates the ending value of prop (the target object property to be tweened).

duration A number that indicates the length of time of the tween motion. If omitted, the duration is set to infinity by default.

useSeconds A Boolean value related to the value you specify in the duration parameter, which indicates to use seconds if true, or frames if false.

For example, imagine that you want to move a movie clip across the Stage. You can add keyframes to a timeline and insert a motion or shape tween between them, you can write some code in an onEnterFrame event handler, or you can use the setInterval() function to call a function at periodic intervals. If you use the Tween class, you have another option that lets you modify a movie clip's _x and _y properties. You can also add the previously described easing methods. To take advantage of the Tween class, you can use the following ActionScript:

new mx.transitions.Tween(ball_mc, "_x", mx.transitions.easing.Elastic.easeOut, 0, 300, 3, true);

This ActionScript snippet creates a new instance of the Tween class, which animates the ball_mc movie clip on the Stage along the x-axis (left to right). The movie clip animates from 0 pixels to 300 pixels in three seconds, and the ActionScript applies an elastic easing method. This means that the ball extends past 300 pixels on the x-axis before using a fluid motion effect to animating back.

For a sample source file that adds scripted animation using the Tween and TransitionManager classes, tweenProgress.fla, see the Flash Samples page at www.adobe.com/go/learn_fl_samples. Download the Samples zip file and navigate to the ActionScript2.0/Tween ProgressBar folder to access this sample.


Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00000964.html