Sunday 27 November 2011

Action Script


The Timer Class is used to execute any code repeatedly after certain time periods. For example, in the movie shown above we are using the Timer Class to make the movie clip rotate a little bit more every second. In code terms, this is done by the Timer Class by triggering an event called TIMER at the specified interval which are then caught using an event listener.
In order to use the Timer Class the following procedure must be followed:
  1. Create an instance of the Timer Class and set the delay period and the repeat count when as you create the new instance.
  2. Listen to the TimerEvent.TIMER using the .addEventListener method.
  3. Create your event listener function to execute the code you wish to run repeatedly.
  4. Start your timer using the .start() method.
The generalized code below illustrates this whole procedure.
var myIndetifier:Timer = new Timer(delay, repeat-count);
myIdentifier.addEventListener(TimerEvent.TIMER, timerListener);
function timerListener (e:TimerEvent):void{
//commands
}
myIdentifier.start();

No comments:

Post a Comment