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

Flash ActionScript Timer Class Clock Start Counting with Time Delay

This Flash ActionScript Timer Class tutorial shows that the clock will not start immediately when the flash movie is opened. Actually the Timer can be started with any time delay. In this Flash Timer Class tutorial, the time delay is five seconds, i.e. the clock will start counting after five seconds.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

In previous Flash Timer Class animation tutorial, the clock started counting at once when the Flash movie was opened. In some situation, you may want the animation to start a bit later, i.e. time delay (for example, 2 seconds, 5 seconds or longer) when the Flash movie is opened. This Flash Timer Class tutorial will show you how to do animation with time delay.

The complete Flash Movie of this tutorial is shown as above. The timer clock will start counting after five seconds (i.e. 5 seconds time delay) when the Flash movie is opened.

Flash ActionScript Codes:

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

 

//We want myClock to start counting after 5 seconds
//Create a Timer instance that will trigger after 5 seconds (one time only)
var delayClock:Timer = new Timer(5000, 1);

 

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

 

//Add an event listener to the timer object (delayClock)
//The event that listen is called TIMER which will be trigger after 5 seconds when the movie starts
//Every time the TIMER event is triggered, it will call the beginCountingClock function
delayClock.addEventListener(TimerEvent.TIMER, beginCountingClock);

 

function beginCountingClock(evt:TimerEvent):void {

//Remove this event listener that no longer in use
delayClock.removeEventListener(TimerEvent.TIMER, beginCountingClock);

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

}

 

//Display text in the Msg Box
output_txt.text = "The clock will start counting soon.....";

 

//Start the time at zero
var time:Number =0;

 

function countingClock(evt:TimerEvent):void {

//Display text in the Msg Box
output_txt.text = "Counting now!";
//Increase the time by 0.1
time += .1;
//Only need one decimal place of myClock
time = (Math.round(time*10)) / 10;
//Show the time
clock_txt.text = String(time);

}

 

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

Download Flash Source File:

Flash Source File timer-2.fla

Remarks:

Up to now, the Timers were completely lack of control. Sometimes you need to control when to start the Timer and provide a mean to stop the Timer. In the next Flash Timer Class animation tutorial, we will use a Play button to start the Timer and a Stop button to stop the Timer. Please read on....