Quick Tips:Interval
From CASA Framework
The setInterval method is commonly used and often hard to manage; a lot of intervals go uncleared. So in CASA there is the org.casaframework.time.Interval class.
It is very similar to setInterval:
var example_si:Interval = Interval.setInterval(this, "exampleFire", 1000, "Aaron");
this.example_si.start();
function exampleFire(firstName:String):Void {
trace("My first name is: " + firstName);
}
You can stop the interval at any point using the stop method:
this.example_si.stop();
and when you want to delete it forever use:
this.example_si.destroy(); delete this.example_si;
If you ever forget to stop or destroy the Interval and the method it is calling no longer exists it stops itself! Unlike the traditional setInterval that will run and take memory forever if the method is removed.
Now for the fun parts of the Interval class. CASA allows you set the amount of repetitions before stopping. Use it like so:
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("My first name is: " + firstName);
}
It even includes a short hand function for defining single rep calls:
var example_si:Interval = Interval.setTimeout(this, "exampleFire", 1000, "Aaron"); this.example_si.start();
If you ever need to change the delay on the fly you can do that too:
var example_si:Interval = Interval.setInterval(this, "exampleFire", 1000, "Aaron"); this.example_si.start(); //.. some time later this.example_si.changeDelay(3000);
The interval also dispatches numerous events to event observers and allows you to clear intervals in a certain scope, or all running intervals. This class should replace all setIntervals in CASA projects.

