Access keys

Timer

Kind of class: class
Inherits from: Dispatcher
Author: Martijn de Visser
Classpath: org.asapframework.util.timer.Timer
File last modified: Thursday, 13 July 2006, 09:33:59
The Timer class enables the creation of timers that run for a specific number of milliseconds and can optionally run for a specific number of loops.
Generated events : start, stop, pause, resume, progress, loopReady, timerReady. Please note that by default, the Timer does NOT generate progress events. Use either the 'reportProgress' paramter in the start method to enable progress reporting, or set the 'reportProgress' to true. Progress reporting is very CPU INTENSIVE!
Usage:
The following creates and then starts a Timer with an infinite number of 2 second loops:
myTimer:Timer = new Timer(2000);
myTimer.start();
This creates a timer that runs 2 one second loops:
myTimer:Timer = new Timer(1000, 2 );
myTimer.start();
Events broadcast to listeners:
TimerEvent with type: PROGRESS
TimerEvent with type: LOOPREADY
TimerEvent with type: READY
TimerEvent with type: START
TimerEvent with type: STOP
TimerEvent with type: PAUSE
TimerEvent with type: RESUME
TimerEvent with type: RESET

Constructor

Timer

function Timer (
inDuration:Number, inLoops:Number, inInterval:Number, inStartTimer:Boolean)
Constructor
Parameters:
nDuration:
(Number) Optional, number of milliseconds to run.
loops :
(Number) Optional, number of loops to run. Defaults to 1 when ommitted.
interval :
(Number) Optional, specifies how often the Timer is updated. Default is 50 milliseconds (e.g. 20 times a second).
start :
(Boolean) Optional, if true, immediately starts the Timer after creation. Default is false.

Instance properties

duration

duration:Number
(read,write)

interval

interval:Number
(write)

loop

loop:Number
(read)

loopPercentage

loopPercentage:Number
(read)

loopProgress

loopProgress:Number
(read)

loops

loops:Number
(read,write)

paused

paused:Boolean
(read)

reportProgress

reportProgress
(write)

running

running:Boolean
(read)

totalPercentage

totalPercentage:Number
(read)

totalProgress

totalProgress:Number
(read)

Instance methods

pause

function pause (
) : Void
Pauses the timer.
Usage:
Timer.pause();
Events broadcast to listeners:
TimerEvent with type: PAUSE

reset

function reset (
) : Void
Resets the timer (same as a .stop(), followed by a .start()).
Usage:
Timer.reset();
Events broadcast to listeners:
TimerEvent with type: RESET

resume

function resume (
) : Void
Resumes the timer.
Usage:
Timer.resume();
Events broadcast to listeners:
TimerEvent with type: RESUME

start

function start (
inDuration:Number, inReportProgress:Boolean) : Void
Starts the timer.
Parameters:
inDuration :
(Number) Number of milliseconds / loop. Optional when already set on construction.
inReportProgress:
(Boolean) optional, set to true to have the time report loop progress. CPU INTENSIVE!
Usage:
Timer.start( nDuration );
Events broadcast to listeners:
TimerEvent with type: START

stop

function stop (
) : Void
Stops the timer.
Usage:
Timer.stop();
Events broadcast to listeners:
TimerEvent with type: STOP

toString

function toString (
) : String