Basic Timer Class Clock Animation with ActionScript
This Flash ActionScript animation tutorial series show how to do animation with Timer Class. Animation with Timer Class is very easy and simple without much coding. The first tutorial use Timer Class to animate a clock. This is a very basic counting digital clock but it shows how Timer Class works.
Flash Tutorial Content:
Animation with Timer Class with ActionScript 3 is simple and easy without writting much coding. The Timer Class is simply to control when and how often a specify function will be called .
The complete Flash Movie of this tutorial is shown as above. The timer clock will be start counting 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);
//Timer object created will not start automatically
//You have to start it
myClock.start();
//Start the time at zero
var time:Number =0;
function countingClock(evt:TimerEvent):void {
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:
Remarks:
In this Flash ActionScript 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 (for example, 2 seconds, 5 seconds or longer) when the Flash movie is opened. The next Flash Timer Class animation tutorial will show you how to do that.