Fun with Intervals [Archive
URL] [Comments:
4]
There are several tricks to working with
Intervals that makes them easy to manage and change.&
The ids for
intervals are numbers globally in the player. When you create an interval with
setInterval, it returns a unique id for the interval you set starting with 1 and
iterating higher.
myInterval =
setInterval(function(){trace('I1')},100) trace(myInterval)
//1
myInterval =
setInterval(function(){trace('I2')},100) trace(myInterval)
//2
myInterval =
setInterval(function(){trace('I3')},100) trace(myInterval)
//3
//clearing the intervals you have set it even
easier.
clearInterval(1) clearInterval(2) clearInterval(3)
Another
interesting patterns is creating a generic Interval function that you can add
functions into. The following function will attempt to execute every object
stored within the function.
intervalCore = function(){ var
self = arguments.callee for( var x in self) self[x]() } myInterval =
setInterval(intervalCore,100)
intervalCore.one =
function(){trace('one')} intervalCore.two =
function(){trace('two')} intervalCore.three =
function(){trace('three')}
//delete the items in the
interval:
delete intervalCore.one delete intervalCore.two delete
intervalCore.three
Or if you simply want to clear out all the
Intervals within the Flash Player:
i =
setInterval(function(){},100) +
1 while(i--){ clearInterval(i) }
Cheers,
Ted ;) |