I use the setTimeout() function through my application but when its time to garbage collect. the method still runs and calls on a function. How do I stop it from calling on a certain function. I tried setting it to null but it doesnt work
`clearInterval()` is for killing a `setInterval()`, not a `setTimeout()`.
Jonathan Sampson
2010-02-04 06:57:07
+4
A:
setTimeout returns an reference to the timeout, which you can then use when you call clearTimeout.
var myTimeout = setTimeout(...);
clearTimeout(myTimeout);
Matt Huggins
2010-02-03 22:35:21
Timeouts only occur once after X seconds, while intervals are used to repeat a timeout every X seconds. I guess clearInterval behaves the same as clearTimeout in whatever browser you're testing, but I'd make sure it works in all browsers if you're trying to use clearInterval on a timeout, and not on an interval.
Matt Huggins
2010-02-04 19:41:02
A:
Ditto. Use "clearInterval(timeoutInstance)".
If you are using AS3, I'd use the Timer() class
import flash.utils.*;
var myTimer:Timer = new Timer(500);
myTimer.addEventListener(“timer”, timedFunction);
// Start the timer
myTimer.start();
function timedFunction(e:TimerEvent)
{
//Stop timer
e.target.stop();
}
JONYC
2010-02-04 06:54:31