Friday 11 October 2013

History of timer class in as3

The Timer class is the interface to timers, which let you run code on a specified time sequence. Use the start() method to start a timer. Add an event listener for the timer event to set up code to be run on the timer interval.
You can create Timer objects to run once or repeat at specified intervals to execute code on a schedule. Depending on the SWF file's frame rate or the runtime environment (available memory and other factors), the runtime may dispatch events at slightly offset intervals. For example, if a SWF file is set to play at 10 frames per second (fps), which is 100 millisecond intervals, but your timer is set to fire an event at 80 milliseconds, the event will be dispatched close to the 100 millisecond interval. Memory-intensive scripts may also offset the events.

TimerExample :- 

The following example uses the class TimerExample to show how a listener method timerHandler() can be set to listen for a new TimerEvent to be dispatched. The timer is started when start() is called, and after that point, the timer events are dispatched.

package {
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.display.Sprite;

    public class TimerExample extends Sprite {

        public function TimerExample() {
            var myTimer:Timer = new Timer(1000, 2);
            myTimer.addEventListener("timer", timerHandler);
            myTimer.start();
        }

        public function timerHandler(event:TimerEvent):void {
            trace("timerHandler: " + event);
        }
    }
}


Public Properties :-

currentCount : int
[read-only] The total number of times the timer has fired since it started at zero.
delay : Number
The delay, in milliseconds, between timer events. 
repeatCount : int
The total number of times the timer is set to run.
running : Boolean
[read-only] The timer's current state; true if the timer is running, otherwise false.




Public Methods :- 

Timer(delay:Number, repeatCount:int = 0)
Constructs a new Timer object with the specified delay and repeatCount states.
reset():void
Stops the timer, if it is running, and sets the currentCount property back to 0, like the reset button of a stopwatch.
start():void
Starts the timer, if it is not already running.
stop():void
Stops the timer.

Events :- 

timer  - Dispatched whenever a Timer object reaches an interval specified according to the Timer.delay property.
timerComplete - Dispatched whenever it has completed the number of requests set by Timer.repeatCount.

No comments:

Post a Comment