Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

Timer Class Reciprocal Animation Flash ActionScript Tutorial

This Flash Timer Class animation shows how to do a reciprocal animation or sequence animation with Timer Class. A movie clip (a bird) on the stage will be rotate up and down infinitely.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

In this Flash ActionScript Timer Class tutorial, we do a simple flash sequence animation with Timer Class.

The complete Flash Movie of this tutorial is shown as above. The bird is looking down and up infinitely.

Flash ActionScript Codes:

//Tween class lets you to move, resize, and fade movie clips
import fl.transitions.Tween;

//easing classes lets you do some elastic motion of movie clips
import fl.transitions.easing.*;

//import the TweenEvent class
//allow create a listener to catch the event when a tween finish.
import fl.transitions.TweenEvent;

//Declare and use later
var tweenRotationBody:Tween;
var tweenRotationTail:Tween;
var rotateDirection:String;

 

//Create a Timer object and store it in a variable called myClock.
//The timer will trigger every 3000 milliseconds (3 seconds)
//1000 milliseconds = 1 second
//3000 milliseconds = 3 seconds
//The repeatCount is zero, i.e. timer will trigger infinitely
//Summary:
//Create a Timer instance that will trigger every 3 seconds infinitely
var myClock:Timer = new Timer(3000, 0);

 

//Timer object created will not start automatically
//You have to start it
myClock.start();

 

//Add an event listener to the timer object (myClock)
//The event that listen is called TIMER which will be trigger every 3 seconds
//Every time the TIMER event is triggered, it will call the birdRotation function
myClock.addEventListener(TimerEvent.TIMER, birdRotation);

 

//Set the bird rotation direction
rotateDirection = "down";

 

//Function to rotate the bird's body and tail
//The rotation direction depends on the value of rotateDirection
function birdRotation(evt:TimerEvent):void {

if (rotateDirection == "down") {//Set rotation direction
rotateDirection = "up"
//Bird's body rotation DOWN tween animation
tweenRotationBody = new Tween(bird_mc, "rotation", Regular.easeOut, 0, 10, 2.5, true);
//Bird's Tail rotation UP tween animation
tweenRotationTail = new Tween(tail_mc, "rotation", Regular.easeOut, 0, 10, 2.5, true);
} else {//Set rotation direction
rotateDirection = "down"
//Bird's body rotation UP tween animation
tweenRotationBody = new Tween(bird_mc, "rotation", Regular.easeOut, 10, 0, 2.5, true);
//Bird's Tail rotation DOWN tween animation
tweenRotationTail = new Tween(tail_mc, "rotation", Regular.easeOut, 10, 0, 2.5, true);
}

}

Download Flash Source File:

Flash Source File timer-5.fla

Remarks:

Up to now, we use only one Timer in our Flash Movies. Actually you can use more than one Timer in a Flash Movie. In the next Flash ActionScript Timer Class tutorial, we will use three Timers to do a more interesting animation.