Click to See Complete Forum and Search --> : Question about setInterval in Flash 8
liuhuan
09-10-2006, 12:10 PM
I was always wondering about how to use setInterval correctly in Flash 8 , as I can't clearly know the meaning of this script . Could anyone who can explain a bit for me ? Thanks in advance!
liuhuan
09-10-2006, 12:16 PM
Is there any difference in setting setInterval in functions and in root timeline?
Patrick Shannon
09-10-2006, 06:32 PM
setInterval keeps a function repeating indefinitely. Here's an example:
function setIntervalExample() {
trace("This message will repeat ten times.");
loopThis++;
if (loopThis >= 10) {
clearInterval(testInterval);
}
}
var testInterval:Number = setInterval(setIntervalExample, 1000);
Basically that trace message would repeat indefinitely if I had not put that if/else loopThis statement to clear the interval after ten times. The "1000" in the testInterval variable is the milliseconds it repeats so you can speed it up or slow it down by playing with the number.
liuhuan
09-11-2006, 12:31 AM
Thanks very much !!
A few other questions , how about if I define the Interval in function ?
For example :
function myfunction(){
var testInterval = setInterval(this , setIntervalExample, 1000);
}
function setIntervalExample(){
trace("This message will repeat ten times.");
loopThis++;
if (loopThis >= 10) {
clearInterval(testInterval);
}
}
myfunction();
Do these codes have the same results with your code ?