Wednesday, 22 September 2010

SetInterval

I hardly ever use this, but in all honesty, it is very useful.

The code below is what I have used for a button which starts or stops the setInterval method. This is AS2 code.

var methInterval = null;
btn.onRelease = function () {
if(methInterval == null) {
methInterval = setInterval(meth,200);
} else {
clearInterval(methInterval);
methInterval = null;
}
}

There may be a more graceful way to do this, but this worked for me. If you trace the interval after clearing it, you get numbers anyway, and I think the number goes up by one each time you set it, so why not just set it to null when you are not using it?!

No comments:

Post a Comment

Please enter your message here...