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

Sequence Animation with Multiple Timers Flash ActionScript Tutorial

In fact, you can use more than one Timer in a Flash Movie depends on the complexity of your flash animation. We will use three Timers in this tutorial to do an interesting flash animation.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

In this Flash ActionScript Timer Class animation tutorial, we do a more interesting flash animation with Timer Class. We use three Timers to do the flash animation in the Flash movie.

The complete Flash Movie of this tutorial is shown as above.

- the bird is looking down and up infinitely (Timer 1), and

- the bee is flying from the left to the right with random position (Timer 2),

- moreover the body of bee is also rotating (Timer 3).

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);
}

}

 

//Function to obtain a random number between two numbers.
function getRandom(minNumber, maxNumber):Number{

var tNumber:Number;
tNumber = Math.round(Math.random()*(maxNumber - minNumber)) + minNumber;
return tNumber;

}

 

//Create a Timer instance that will trigger every 0.1 seconds infinitely
//This Timer is used to move the bee flying from left to right
var beeMove:Timer = new Timer(100, 0);

 

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

 

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

 

function beeFly(evt:TimerEvent):void {

if (bee_mc.x < 530) {bee_mc.x += 3;
bee_mc.y += 0.5;
} else {bee_mc.x = -10;
bee_mc.y = getRandom(50, 150);
}

}

 

//Create a Timer instance that will trigger every 8 seconds infinitely
//This Timer is used to move the bee flying from left to right
var beeRotate:Timer = new Timer(8000, 0);

 

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

 

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

 

var beeRotation:String = "rotateRight";

 

function beeRotateBody(evt:TimerEvent):void {

if (beeRotation == "rotateRight") {var tweenRotation1:Tween = new Tween(bee_mc, "rotation", Regular.easeOut, 0, 30, 5, true);
beeRotation = "rotateLeft";
} else if (beeRotation == "rotateLeft") {var tweenRotation2:Tween = new Tween(bee_mc, "rotation", Regular.easeOut, 30, 0, 5, true);
beeRotation = "rotateRight";
}

}

Download Flash Source File:

Flash Source File timer-6.fla

Remarks:

This Flash ActionScript Timer Class tutorial showed how to do sequence animation with multiple timers.