.tmp_159A79F8238D8C1E1ACBA4D5AD09FDB9_LFC-$86.lzx
<canvas height="200" width="200">
<class name="loopingtimer" extends="view">
<switch>
<when property="$as3">
<passthrough>
import flash.utils.setTimeout;
</passthrough>
</when>
</switch>
<attribute name="timer_resolution" type="number" value="40
"/>
<attribute name="formertime" type="number" value="0
"/>
<attribute name="currenttime" type="number" value="0
"/>
<attribute name="timer_state" type="string" value="PAUSED
"/>
<method name="reactToTimeChange" args="theTime">
if ($debug){
Debug.write('WARNING: reactToTimeChange(): This is an abstract method that should be overridden to do something useful in your application');
Debug.write('reactToTimeChange(): Time elapsed since last firing in milliseconds: '+theTime);
}
</method>
<method name="startTimer">
this.setAttribute('timer_state', 'COUNTING');
var now = new Date();
var rawTime = now.getTime();
this.setAttribute('formertime', rawTime);
this.doForTime();
</method>
<method name="pauseTimer">
this.setAttribute('timer_state', 'PAUSED');
</method>
<method name="unpauseTimer">
this.setAttribute('timer_state', 'COUNTING');
var now = new Date();
var rawTime = now.getTime();
this.setAttribute('formertime', rawTime-this.currenttime);
this.repeat();
</method>
<method name="stopTimer">
this.pauseTimer();
this.resetTimer();
</method>
<method name="resetTimer">
this.setAttribute('formertime', 0);
this.setAttribute('currenttime', 0);
</method>
<method name="seekToTime" args="iTimeMs">
this.setAttribute('currenttime', Math.floor(iTimeMs));
</method>
<method name="doForTime">
// Prevent Timer Incrementing When Paused
if (this.timer_state == 'PAUSED')
return;
var now = new Date();
var rawTime = now.getTime();
if (this.formertime != 0)
var currentTime = rawTime - this.formertime;
this.setAttribute('currenttime', currentTime);
// Call Abstract Method:
this.reactToTimeChange(currentTime);
this.repeat();
</method>
<method name="repeat">
// This function uses an embedded JavaScript function which
// can be called via the standard JavaScript setTimeout()
// method which results in more accurate timer firing then the
// standard OpenLaszlo LzTimer() class. LzTimer() fired up to
// 256ms late, while setTimeout() usually fires from
// only 47ms-78ms
var f = function(){
doForTime();
}
setTimeout(f, this.timer_resolution);
</method>
</class>
<loopingtimer/>
</canvas>