Interval

Kind of class:public class
Package:org.casalib.time
Inherits from:Timer
Implements:
Version:09/06/09
Author:Aaron Clinger, Mike Creighton
Classpath:org.casalib.time.Interval
File last modified:Sunday, 06 September 2009, 08:45:59
To be used instead of flash.utils.setInterval and flash.utils.setTimeout functions.

Advantages over setInterval/setTimeout:
  • Ability to stop and start intervals without redefining.
  • Change the time (delay), call back and arguments without redefining.
  • Included repeatCount for intervals that only need to fire finitely.
  • setInterval and setTimeout return an object instead of interval id for better OOP structure.
  • Built in events/event dispatcher.
Example:
  • package {
        import org.casalib.display.CasaMovieClip;
        import org.casalib.time.Interval;
    
    
        public class MyExample extends CasaMovieClip {
            protected var _interval:Interval;
    
    
            public function MyExample() {
                super();
    
                this._interval = Interval.setInterval(this._repeatingFunction, 1000, "CASA");
                this._interval.repeatCount = 3;
                this._interval.start();
            }
    
            protected function _repeatingFunction(name:String):void {
                trace(name);
            }
        }
    }

Summary


Instance properties
  • callBack : Function
    • The function to execute after specified delay.
  • arguments : Array
    • The arguments to be passed to the call back function when executed.
  • destroyed : Boolean
Class methods
  • setInterval (callBack:Function, delay:Number, arguments) : Interval
    • Runs a function at a specified periodic interval.
  • setTimeout (callBack:Function, delay:Number, arguments) : Interval
    • Runs a function at a specified periodic interval.
Instance methods
  • removeEventsForType (type:String) : void
    • Removes all events of a specific type.
  • removeEventsForListener (listener:Function) : void
    • Removes all events that report to the specified listener.
  • removeEventListeners : void
    • Removes all event listeners.
  • destroy : void
    • Removes any event listeners and stops all internal processes to help allow for prompt garbage collection.

Instance properties

arguments

public arguments:Array
(read,write)

The arguments to be passed to the call back function when executed.

callBack

public callBack:Function
(read,write)

The function to execute after specified delay.

destroyed

public destroyed:Boolean
(read)

Class methods

setInterval

public static function setInterval (
callBack:Function, delay:Number, arguments) : Interval

Runs a function at a specified periodic interval.
Parameters:
callBack :
The function to execute after specified delay.
delay :
The time in milliseconds between calls.
arguments:
The arguments to be passed to the call back function when executed.
Returns:

setTimeout

public static function setTimeout (
callBack:Function, delay:Number, arguments) : Interval

Runs a function at a specified periodic interval. Acts identically like setInterval except setTimeout defaults repeatCount to 1.
Parameters:
callBack :
The function to execute after specified delay.
delay :
The time in milliseconds between calls.
arguments:
The arguments to be passed to the call back function when executed.
Returns:

Instance methods

destroy

public function destroy (
) : void

Removes any event listeners and stops all internal processes to help allow for prompt garbage collection.

Always call flash.utils.setInterval before deleting last object pointer.
#
Specified by:

removeEventListeners

public function removeEventListeners (
) : void

Removes all event listeners.
#

removeEventsForListener

public function removeEventsForListener (
listener:Function) : void

Removes all events that report to the specified listener.
#
Parameters:
listener:
The listener function that processes the event.
#

removeEventsForType

public function removeEventsForType (
type:String) : void

Removes all events of a specific type.
#
Parameters:
type:
The type of event.
#