Access keys

Interval

Kind of class: class
Inherits from: EventDispatcher < CoreObject
Implements:
Version: 12/14/06
Author: Aaron Clinger, Toby Boudreaux, Mike Creighton
Classpath: org.casaframework.time.Interval
File last modified: Wednesday, 24 January 2007, 21:45:40
To be used instead of built in setInterval function.


Advantages over setInterval:
  • Auto stopping/clearing of intervals if method called no longer exists.
  • Ability to stop and start intervals without redefining.
  • Change the delay with changeDelay without redefining.
  • Included setReps for intervals that only need to fire finitely.
  • setInterval returns object instead of interval id for better OOP structure.
  • Built in events/event dispatcher.
Example:
var example_si:Interval = Interval.setInterval(this, "exampleFire", 1000, "Aaron");
this.example_si.setReps(3);
this.example_si.start();

function exampleFire(firstName:String):Void {
    trace("exampleFire called and passed firstName = " + firstName);
}
Events broadcast to listeners:
onStart = function (sender:Interval) {}
onStop = function (sender:Interval) {}
onFire = function (sender:Interval, fires:Number) {}
onComplete = function (sender:Interval, fires:Number) {}

Class properties

EVENT_COMPLETE

static EVENT_COMPLETE:String = 'onComplete'
(read,write)

EVENT_FIRE

static EVENT_FIRE:String = 'onFire'
(read,write)

EVENT_START

static EVENT_START:String = 'onStart'
(read,write)

EVENT_STOP

static EVENT_STOP:String = 'onStop'
(read,write)

Class methods

setInterval

static function setInterval (
scope:Object, methodName:String, delay:Number, param:Object) : Interval
Calls a function or a method of an object at periodic intervals.
Parameters:
scope :
An object that contains the method specified by "methodName".
methodName:
A method that exists in the scope of the object specified by "scope".
delay :
The time in milliseconds between calls.
param(s) :
[optional] Parameters passed to the function specified by "methodName". Multiple parameters are allowed and should be separated by commas: param1,param2, ...,paramN
Returns:
Interval reference.

setTimeout

static function setTimeout (
scope:Object, methodName:String, delay:Number, param:Object) : Interval
Calls a function or a method of an object once after time has elasped, setTimeout defaults setReps to 1.
Parameters:
scope :
An object that contains the method specified by "methodName".
methodName:
A method that exists in the scope of the object specified by "scope".
delay :
The time in milliseconds until call.
param(s) :
[optional] Parameters passed to the function specified by "methodName". Multiple parameters are allowed and should be separated by commas: param1,param2, ...,paramN
Returns:
Interval reference.

stopIntervals

static function stopIntervals (
scope:Object) : Void
Stops all intervals in a defined location.
Parameters:
scope:
[optional] Object reference that contains a method referenced by one or more Interval instance. If scope is undefined, stopIntervals will stop all running intervals.
See also:

Instance methods

changeDelay

function changeDelay (
delay:Number) : Void
Changes the time between repetitions. Does NOT reset reps/fires.
Parameters:
delay:
The time in milliseconds between calls.

destroy

function destroy (
) : Void
Removes internal variables, intervals, enter frames, internal MovieClips and event observers to allow the object to be garbage collected.

Always call destroy() before deleting/removing object instance.
#

getFires

function getFires (
) : Number
Returns the number of fires.
Returns:
The number of elapsed fires.

isFiring

function isFiring (
) : Boolean
Returns:
Returns true if interval instance is running/firing; otherwise false.

setReps

function setReps (
reps:Number) : Void
Defines the amount of total repetitions/fires. If not set repetitions will continue until stop is called.
Parameters:
reps:
Number of repetitions.

start

function start (
) : Void
Starts or restarts the interval method calls. Resets reps/fires to 0.
Events broadcast to listeners:
onStart = function (sender:Interval) {}

stop

function stop (
) : Void
Stops the interval method calls. Used instead of clearInterval. Always call before deleting reference instance.
Events broadcast to listeners:
onStop = function (sender:Interval) {}