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, 13:48:48
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 broadcasted to listeners:

Summary


Constructor
  • Timer (inDuration:Number, inLoops:Number, inInterval:Number, inStartTimer:Boolean)
    • Constructor
Instance properties
Instance methods
  • update : Void
  • start (inDuration:Number, inReportProgress:Boolean) : Void
    • Starts the timer.
  • stop : Void
    • Stops the timer.
  • pause : Void
    • Pauses the timer.
  • resume : Void
    • Resumes the timer.
  • reset : Void
    • Resets the timer (same as a .stop(), followed by a .start()).
  • toString : String

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

bPaused

private bPaused:Boolean
(read)

Parameters:
event :
(String) Required; event to subscribe listener to.
listener:
(Object) The listener object to subscribe to the specified event.
Usage:
  • Timer.addEventListener(event, listener)

bReportProgress

private bReportProgress:Boolean
(read)

bRunning

private bRunning:Boolean
(read)

duration

duration:Number
(read,write)

interval

interval:Number
(write)

intervalID

private intervalID:Number
(read)

loop

loop:Number
(read)

loopPercentage

loopPercentage:Number
(read)

loopProgress

loopProgress:Number
(read)

loops

loops:Number
(read,write)

nDuration

private nDuration:Number
(read)

nLoop

private nLoop:Number
(read)

nLoops

private nLoops:Number
(read)

paused

paused:Boolean
(read)

playTime

private playTime:Number
(read)

reportProgress

reportProgress
(write)

running

running:Boolean
(read)

startTime

private startTime:Number
(read)

totalPercentage

totalPercentage:Number
(read)

totalProgress

totalProgress:Number
(read)

updateInterval

private updateInterval:Number
(read)

Instance methods

pause

function pause (
) : Void

Pauses the timer.
Usage:
  • Timer.pause();
Events broadcasted to listeners:

reset

function reset (
) : Void

Resets the timer (same as a .stop(), followed by a .start()).
Usage:
  • Timer.reset();
Events broadcasted to listeners:

resume

function resume (
) : Void

Resumes the timer.
Usage:
  • Timer.resume();
Events broadcasted to listeners:

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 broadcasted to listeners:

stop

function stop (
) : Void

Stops the timer.
Usage:
  • Timer.stop();
Events broadcasted to listeners:

toString

function toString (
) : String

update

private function update (
) : Void

Events broadcasted to listeners: