Start your Flash program. Select "New" from the "File" menu on the main Flash menu bar. Select the "ActionScript 3" file option from the dialog box.
Select the "Actions" option from the "Window" menu on the main Flash menu bar to open the "Actions" editor. Position your mouse cursor on the first line in the Actions editor. Type the code to import the "transition" classes needed to code a Tween. Type the import code as three separate lines to include the "Tween" and the "easing" and the "TweenEvent" classes as shown below.
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
;
Code a red circle shape object and place it on the stage. Use an unsigned integer (uint) variable to store the hexadecimal code equivalent of red (ff0000), a Shape instance called "ball" to define a shape, the lineStyle method to assign a 1 pixel black border to the shape, the drawCircle method to define the initial position of the circle's center and its radius, the beginFill and endFill methods to color the circle the assigned red color and the addChild method to place the circle on the stage (screen). Type the AS3 code listed below in the Actions Editor to draw an place the red circle on the stage.
var color: uint = 0xff0000;
var ball:Shape= new Shape();
ball.graphics.lineStyle(1);
ball.graphics.beginFill(color);
ball.graphics.drawCircle(100,100,100)
ball.graphics.endFill()
stage.addChild(ball)
var bounce:Tween = new Tween(ball, 'y', Bounce.easeIn, 0, 300, 3, true);
Code a tween to bounce the "ball" object. Set the parameters in the "Tween" statement as "ball" for the object you want to tween, "y" as the direction you want to bounce the ball in (vertical), "Bounce.easeIn" to specify a bounce that starts off slow, the number zero (0) as the starting position on the y-axis to begin the bounce, the number 300 as the ending position on the y-axis of the object at the end of the tween, 3 as the time duration of the bounce, and true to specify that the time, 3, is in seconds. Assign and create the Tween to an object named "bounce" with the code below.
var bounce:Tween = new Tween(ball, 'y', Bounce.easeIn, 0, 300, 3, true);
Type the latter statement as the last line on the code already entered as follows:
var color: uint = 0xff0000;
var ball:Shape= new Shape();
ball.graphics.lineStyle(1);
ball.graphics.beginFill(color);
ball.graphics.drawCircle(100,100,100)
ball.graphics.endFill()
stage.addChild(ball)
var bounce:Tween = new Tween(ball, 'y', Bounce.easeIn, 0, 300, 3, true);
Select "TestMovie" from the "Control" menu on the main Flash menu bar. Observe that a red circle starts to move slowly downward and then bounces back up to the top of the screen. Also observe that the bounce lasts for 3 seconds, the time specified.