This content has been marked as final. Show 3 replies
The whole point of setInterval is that is repeats forever at the duration you set – or until it is cleared. So if you want this to keep repeating remove the clearInterval. Also I'm not sure what is going on with the conditional, it seems to be incrementing each time, and then when it has gone through the array once it won't reset the interval anymore.
Instead of hard coding the maxCount, I would use the actual length of the array. And instead of using it to decide when to stop your interval I would use it to check when you needed to start over again:
Rothrock, That did it.
Thanks for the reply. I changed the clearInterval to count = 0, and now on and on it goes.
It seems so simple after your explanation. Not sure why, but even after pouring over the Flash docs on this, I'm still having trouble getting my head around using setInterval.
Anyway, thanks again.
Yes, it does seem to be one of those things that a lot of folks struggle with – I did too way back.
Just remember that it means, "keep doing what I tell you at the agreed upon interval – until you are told to stop." I think assigning the return value to a variable is a big part of the confusion. Really it is just like getting a ticket in a bakery. There can be many interval running at the same time, so to keep them straight flash gives them a number – the first one is 1, the next 2, and so on.
So all that we are doing with the assigning to a variable is pulling the bakery ticket out of the machine and hanging on to it. There is no way to know what the number will be until we pull it out or what it was if we lose it. So we have to keep it around (by putting it in a variable). Then later we can say, "Oh yeah, remember interval 5, well cancel it now."
Remember too, that the internal Flash classes may also use setInterval so you can never count on, "Well the last interval I used was 4, so this next one will be 5."