Class org.aswing.utils.Timer

Description

Fires one or more action events after a specified delay. For example, an animation object can use a Timer as the trigger for drawing its frames.

Setting up a timer involves creating a Timer object, registering one or more action listeners on it, and starting the timer using the start method. For example, the following code creates and starts a timer that fires an action event once per second (as specified by the first argument to the Timer constructor). The second argument to the Timer constructor specifies a listener to receive the timer's action events.

  var delay:Number = 1000; //milliseconds
  var listener:Object = new Object();
  listener.taskPerformer = function() {
          //...Perform a task...
      }
  var timer:Timer = new Timer(delay);
  timer.addActionListener(listener.taskPerformer, listener);
  timer.start();
 

Field Index

Inherited from EventDispatcher

Method Index

new Timer()
addActionListener(), getDelay(), getInitialDelay(), isRepeats(), isRunning(), restart(), setDelay(), setInitialDelay(), setRepeats(), start(), stop()

Inherited from EventDispatcher

Constructor Detail

Timer

public function Timer(delay:Number)

Construct Timer.

Throws

Errorwhen init delay <= 0 or delay == null

See Also

Method Detail

addActionListener

public function addActionListener(func:Function, obj:Object):Object

Adds an action listener to the Timer.

Parameters

functhe listener function
objthe listener obj

Return

the listener just added.

See Also

setDelay

public function setDelay(delay:Number):Void

Sets the Timer's delay, the number of milliseconds between successive events.

Parameters

delaythe delay in milliseconds

Throws

Errorwhen set delay <= 0 or delay == null

See Also

getDelay

public function getDelay():Number

Returns the delay, in milliseconds, between firings of events.

See Also

setInitialDelay

public function setInitialDelay(initialDelay:Number):Void

Sets the Timer's initial delay, which by default is the same as the between-event delay. This is used only for the first action event. Subsequent events are spaced using the delay property.

Parameters

initialDelaythe delay, in milliseconds, between the invocation of the start method and the first event fired by this timer

Throws

Errorwhen set initialDelay <= 0 or initialDelay == null

See Also

getInitialDelay

public function getInitialDelay():Number

Returns the Timer's initial delay.

See Also

setRepeats

public function setRepeats(flag:Boolean):Void

If flag is false, instructs the Timer to send only once action event to its listeners after a start.

Parameters

flagspecify false to make the timer stop after sending its first action event. Default value is true.

isRepeats

public function isRepeats():Boolean

Returns true (the default) if the Timer will send an action event to its listeners multiple times.

See Also

start

public function start():Void

Starts the Timer, causing it to start sending action events to its listeners.

See Also

isRunning

public function isRunning():Boolean

Returns true if the Timer is running.

See Also

stop

public function stop():Void

Stops the Timer, causing it to stop sending action events to its listeners.

See Also

restart

public function restart():Void

Restarts the Timer, canceling any pending firings and causing it to fire with its initial delay.