In this tutorial, we are going to learn how to Tween objects on stage using the Tween Class. The Tween Class lets us easily create animations of objects by specifying the property to be tweened and the initial and final values. 
This method is useful to create animations on the fly...  
It is sujjested you read this article on timeline animation and tweening to understand the basics of Timeline aniamtion and Tweening using the timeline before learning to Tween using code.  

 


Preparing the Stage::
Open the Flash application and create a new ActionScript 3 Movie (Ctrl+N). Now we are going to create the object that we wish to animate dynamically for instance create a movieClip on the stage. I have created a circle using the Oval tool (O).

Note:: Holding shift creates while using the oval tool creates a perfect circle. This can be extended to creating squares and stretching proportionately...
 
Now select the movieClip and fireup the properties panel (Ctrl+F3) and change the instance name of the movieClip to "ball_mc".  

This will act as a reference name of the object (movieclip) when writing code and helps the compiler identify the object in the Movie. Right-click frame1 and select Actions and paste this code below...

  
Code::
import fl.transitions.Tween; import fl.transitions.easing.*; import fl.transitions.TweenEvent; var my_tween:Tween = new Tween(ball_mc, "x", Regular.easeIn, 10, 200, 3, true);


Code Description ::


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

In these first three lines of code, we are importing the Tween Class and the entire easing class and all its functions, which we would use to animate objects.

var my_tween:Tween = new Tween(ball_mc, "x", Regular.easeIn, 10, 200, 3, true);

In the left hand side of the above line of code, we are creating a new variable by the instance name of "my_tween" which is an instance of the Tween object defined by the Tween Class we just imported earlier.

The right hand side, we are initializing the Tween object by calling the constructor function of the Tween Class with the following parameters :

instance name of the object to tween - ball_mc
property of the object to tween - "x"
type of easing to be used - Regular.easeIn
initial value of the property - 10
final value of the property - 200
length of the animation - 3
length specified above in seconds - true

Note :: The length of the animation, is taken to be frames if the last parameter is not set as true.
true - length of tween in seconds false - length of tween in number of frames (default value)

Now Test the Movie (Ctrl+Enter) and you should see your movie clip move from along the x-axis from cordinate 10 to 200 over a span of 3 seconds...

This tutorial can be extended to other properties like "alpha", "y", "scaleX" and "scaleY" of the object and also various other easing styles to achieve the preferred animation.

Read the reference for the easing Class here to learn about the various easing styles available...