[osflash] clearInterval quandry
Luke Bayes
lbayes at gmail.com
Fri Nov 11 19:08:39 EST 2005
The single best method I have seen for managing intervals is to store the
intervalId in a new object, then pass a reference of that object to the
interval handler as an argument.
With this, you don't clutter up your classes with interval management member
variables, the called method can execute code in the scope of where it is
declared. and then simply clear the interval whenever it wants to...
public function beginInterval():Void {
var obj:Object = new Object();
obj.id <http://obj.id> = setInterval(this, "doSomething", 200, obj);
}
public function doSomething(obj:Object):Void {
trace("doSomething called with: " + obj.id <http://obj.id>);
this.doSomethingElse();
clearInterval(obj.id <http://obj.id>);
}
public function doSomethingElse():Void {
trace("doSomethingElse called");
}
I haven't tested the code - but it should work...
Good Luck,
Luke Bayes
www.asunit.com <http://www.asunit.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/osflash_osflash.org/attachments/20051111/b2eb9630/attachment.htm
More information about the osflash
mailing list