setInterval
I often see questions about setInterval on flashcoders, so I thought I'd share my comments here. This applies to both Flash and JavaScript programming...
Intervals are not a problem as long as you use them correctly. Just make sure for every setInterval() call you have a corresponding clearInterval() call. Usually the clearInterval() is within your interval event handler function, so once the interval end condition is met, there's no way for your code to exit without hitting it.
I've been doing things this way for a long time, and I can't even remember the last time that I had a runaway interval problem. There's no need for an IntervalManager class if you don't want to deal with that. (Nothing wrong with it, but it might be overkill.)
Of course onEnterFrame is fine too if you're doing something in the context of a MovieClip, but that may not always be the case. And with that there's a danger too that you need to look out for. If a MovieClip already has an onEnterFrame handler -- say something you loaded externally that was created by a different developer -- you could overwrite it!
Intervals are not a problem as long as you use them correctly. Just make sure for every setInterval() call you have a corresponding clearInterval() call. Usually the clearInterval() is within your interval event handler function, so once the interval end condition is met, there's no way for your code to exit without hitting it.
//PSEUDOCODE
var myInterval = setInterval(myFunc, 200);
myFunc(){
//do stuff
if(endCondition == true){
clearInterval(myInterval);
}
}
I've been doing things this way for a long time, and I can't even remember the last time that I had a runaway interval problem. There's no need for an IntervalManager class if you don't want to deal with that. (Nothing wrong with it, but it might be overkill.)
Of course onEnterFrame is fine too if you're doing something in the context of a MovieClip, but that may not always be the case. And with that there's a danger too that you need to look out for. If a MovieClip already has an onEnterFrame handler -- say something you loaded externally that was created by a different developer -- you could overwrite it!