A Utility Class. Its methods can be implemented with Class-implement into any Class. Used to run a class method on a periodical.
Useful in galleries, slideshows, tickers, sprite animations, pulsing, logout scripts, etc. Anything that needs to run the same function repeatedly.
var MyClass = new Class({Implements: Loop});
MyClass.implement(Loop);
number) The current number of loops.boolean) True if looping, false if stopped.boolean) True if stopped, false if looping.var Widget = new Class({
Implements: Loop,
initialize: function(log){
this.setLoop(this.update, 1000);
this.log = document.id(log);
},
update: function(count){
this.log.set('text',"Looped " + count + " times");
}
});
var myWidget = new Widget('log').startLoop();
Assigns the class method, with it's delay, to be looped.
MyClass.setLoop(this.method, 3000);
function) The function to be called on a periodical.number: defaults to 3000) The time in milliseconds passed to the periodical.object) The current Class object.The method assigned to the loop receives the loopCounter argument. As shown in the example above with update.
Stops the periodical.
myInstance.stopLoop();
object) The current Class object.Starts the periodical.
myInstance.startLoop();
number: defaults to the instance delay) The delay for the periodical. Unless defined when called, it will use whatever was set for delay in setLoop(fn,delay).object) The current Class object.Resets loopCount to 0.
myInstance.resetLoop();
object) The current Class object.