// A sample timer component by bleroy /// Type.registerNamespace("Bleroy.Samples"); Bleroy.Samples.Timer = function(interval) { /// A simple timer component. /// /// The time in milliseconds between ticks. /// Bleroy.Samples.Timer.initializeBase(this); this._interval = interval; } Bleroy.Samples.Timer.prototype = { add_tick: function(handler) { /// /// This event fires with a frequency determined by the interval. /// this.get_events().addHandler("tick", handler); }, remove_tick: function(handler) { this.get_events().removeHandler("tick", handler); }, dispose: function() { this.stop(); }, start: function() { /// Starts the timer. this._tickDelegate = Function.createDelegate(this, this._tick); this._timeoutCookie = window.setTimeout(this._tickDelegate, this._interval); }, stop: function() { /// Stops the timer. window.clearTimeout(this._timeoutCookie); delete this._tickDelegate; }, _tick: function() { var handler = this.get_events().getHandler("tick"); if (handler) handler(this, Sys.EventArgs.Empty); this._timeoutCookie = window.setTimeout(this._tickDelegate, this._interval); } } Bleroy.Samples.Timer.registerClass("Bleroy.Samples.Timer", Sys.Component);