In addition to the primitive data types such as int and Number ActionScript has hundreds of special types called classes that are builtin. They can do everything from playing a sound to opening a browser to a particular page.
These special types are called classes and always start with an uppercase letter. WWhen we declare a variable of this type ww must use the word new.
One important class that is very usefiul is the Timer.
In this movie we have a spinning star. Instead of using the frame event, this movie uses a timer.
var spinTimer:Timer=new Timer(50); //how often does the timer go off?
spinTimer.addEventListener(TimerEvent.TIMER,spin); //listen for the timer to go off
spinTimer.start(); //timer is not automatically "set" to go off
function spin(e:TimerEvent): void {
star.rotation=star.rotation+1;
}
The first line declares the timer as type Timer. The next part says that spinTimer is a new instance of the Timer class. Classes can take parameters, the timer has a parameter telling how often we want the timer to go off. We need to listen for the timer to go off, and we also have to start the timer.
We can change the interval either in the variable declaration or through the delay property:
spinTimer.delay=20;
To Do: Change the interval of the timer in the first line to make the star spin faster of slower. Add buttons to change the delay property and make the star spin faster or slower.