This article is a spanzhang original, its blog address is: http://blog.9cbs.net/spanzhang. Please indicate the source, thank you! !
Author: Zhang Youbang Time: 2004-02-27 Description: clock control properties: unit: unit of time, which is itself in milliseconds. The clock will be moved in this unit, and every additional increase will generate an event onUnit. Interval: The number of units (Unit) included in the clock target. UnitCount: The current number of units. Enabled: Clock enabled state. Event: OnUnit: Events generated by each clock. Ontimer: Clock Target Event.
Example: span> ->
//// global variables // var __handleInterval = null; __unitCount __enabled __unit __interval = 10 //// number var = 0var = falsevar = 1000var milliseconds // function putUnit (unitInMS) {__unit = unitInMS __startTimer ()} function getUnit () {RETURN __UNIT} /// Current unit number // function getUnitcount () {return__unitcount} /// actual clock processing function // function __timereventhandler () {__UNITCOUNT EventUnit.fire (createEventObject ()) IF (CreateEventObject ()) IF __unitCount> = __interval) {eventTimer.fire (createEventObject ()) __unitCount = 0}} //// clock control function // function __stopTimer () {if (__handleInterval! = null) {clearInterval (__ handleInterval) __handleInterval = null} __unitCount = 0} function __startTimer () {__stopTimer () __handleInterval = setInterval (__ timerEventHandler, __unit) eventUnit.fire (createEventObject ())} //// clock cycle // function putInterval (intervalInSeconds) {__interval = intervalInSeconds if (__enabled) { __starttimer () // restart}} Function GetInterval () {Return__interval} //// Clock State // Function Putenabled (__enabled == Beenable) Return I f (beEnabled) __startTimer () else __stopTimer () __enabled = beEnabled} function getEnabled () {return __enabled} //// reset // function reset () {__unitCount = 0 if (__enabled) __startTimer ()} script >