setInterval

I have been a Flash developer for a number of years, but until recently, i have not come across the setInterval() function. I have used the onEnterFrame function before, and although it does work properly, you are limited to just repeating at the current frame rate. SetInterval on the other hand, allows for more flexibility by allowing you to specify in milliseconds exactly how much time you want between each repetition of a function.

_root.onEnterFrame = function(){
    refresh();
}

As you have probably already worked out, this code will run the function refresh() again and again every time the frame should be changed, even if there is only one frame in _root. However, the setInterval() will allow the user to define, exactly how often they want the function to repeat. For Instance:

setInterval(doStuff, 2000,"doThis","doThat")
function doStuff(a,b){
trace (a)
trace (b)
}

The Previous code will trace "doThis", and "doThat" once every 2000 miliseconds, or 2 seconds. Also, the Parameters for the setInterval() function are (functionName,timeInMilliseconds,anyParameters).

This Concludes our rundown on the setInterval() function.

If you have any comments or questions please feel free to let us know… and

Thanks for reading

One Response to “setInterval”

  1. mr.Open Says:

    mr.Open

    Cool! Its really cool.

Leave a Reply