Posts Tagged ‘ActionScript 3’

Animating with Tween class

The Tween Class allows you to specify  the compatible display object and property you wish to tween, the precreated easing function that will affect the property change, the beginning and finishing values of the property, the duration of the tween and f inally whether to use seconds or frames when evaluating the tween’s duration. Check this class’s constructor:

Tween (obj:Object, prop:String, func:Function, begin:Number, finish:Number, duration:Number, useSeconds:Boolean)

The following example creates a ball movieclip, places it at point x:100 y:100, and then creates the tween. It alters the x coordinate of the mclip using an elastic easing. It begins at position 100 and finishes at 400, and it takes 3 seconds to complete the tween, the last parameter true indicates useSeconds.

See the final result:

Code:

import fl.transitions.Tween;
import fl.transitions.easing.*;

var ball:MovieClip = new Ball();
ball.x= ball.y=100;
addChild(ball);

var ballXTween:Tween = new Tween(ball,”x”, Elastic.easeInOut,100,400,3,true);

» Download the source file