Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8559961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:10:18+00:00 2026-06-11T16:10:18+00:00

The lz.Timer class in OpenLaszlo can sometimes fire up to 256ms late, how do

  • 0

The lz.Timer class in OpenLaszlo can sometimes fire up to 256ms late, how do you create one that fires more accurately?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:10:19+00:00Added an answer on June 11, 2026 at 4:10 pm

    The following OpenLaszlo timer class I designed will fire more accurately and also has a nice looping feature with pause and reset for ease of use. This code works in OpenLaszlo 4.9.0 SWF10 and DHTML run-times:

    <library>
    
      <!---
      Class: <loopingtimer>
      Extends: <node>
    
      This class is a looping timer that can be used to call a method to peform
      an action repeatedly after a specified number of milliseconds.
    
      Override the abstract method reactToTimeChange(theTime) to do something
      useful in your application, theTime will be the time elapsed since the
      timer's last firing, it will be close to the 'timer_resolution' set but
      will be off from about 47ms-78ms in FireFox 2 and 47ms-94ms in IE6
      (see note below for explanation).
    
      NOTE:
    
      This class originally used the LzTimer class but it was firing up to 256ms
      late, so this has been replaced with a setTimeout() method and embedded
      JavaScript which is more accurate, but still fires about 59ms late on
      average.
    
      For this reason the firing times of this class are approximate but will
      probably fire 47ms to 78ms (about 59ms) on average late. As a workaround
      for this problem the timer uses the system time to calculate how much time
      has actually elapsed since the last timer firing and passes the actual time
      elapsed ('theTime') in milliseconds to the abstract 'reactToTimeChange()'
      method.
    
      -->
      <class name="loopingtimer" extends="node">
    
        <switch>
          <when property="$as3">
            <passthrough>
              import flash.utils.setTimeout;
            </passthrough>
          </when>
        </switch>
    
        <!-- *** ATTRIBUTES *** -->
    
        <!-- Public Attributes -->
    
        <!---
        @param numnber timer_resolution: number of milliseconds between timer
        firings (default: 40ms)
    
        Note: OpenLaszlo seems to typically have a lower limit of 47-78
        milliseconds between firings, so setting below this may be useless.
        -->
        <attribute name="timer_resolution" type="number" value="40" />
    
        <!-- Private Attributes -->
    
        <!--- @keywords private -->
        <!---
        @param number formertime: used internally to calculate the number of
        elapsed milliseconds since playback was started
        -->
        <attribute name="formertime" type="number" value="0" />
    
        <!--- @keywords private -->
        <!---
        Used internally for tracking virtual current time in milliseconds
        for pause functionality.
        -->
        <attribute name="currenttime" type="number" value="0" />
    
        <!--- @keywords private -->
        <!--- @param string timer_state: 'PAUSED' | 'COUNTING' -->
        <attribute name="timer_state" type="string" value="PAUSED" />
    
    
        <!-- *** METHODS *** -->
    
    
        <!-- Public Methods -->
    
    
        <!--- @keywords abstract -->
        <!---
        ABSTRACT METHOD: overwrite to do something useful in your program
    
        @param number theTime: the time in milliseconds elapsed since playback
        was  started
        -->
        <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>
    
        <!--- Start Timer (Note: This will reset timer to 0) -->
        <method name="startTimer">
          this.setAttribute('timer_state', 'COUNTING');
          var now = new Date();
          var rawTime = now.getTime();
          this.setAttribute('formertime', rawTime);
    
          this.doForTime();
        </method>
    
        <!--- Pauses timer at current time -->
        <method name="pauseTimer">
          this.setAttribute('timer_state', 'PAUSED');
        </method>
    
        <!--- Resumes timer from time it is paused at -->
        <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>
    
        <!--- Stop Timer - stops timer and resets to 0  -->
        <method name="stopTimer">
          this.pauseTimer();
          this.resetTimer();
        </method>
    
        <!--- Resets Timer to 0 -->
        <method name="resetTimer">
          this.setAttribute('formertime', 0);
          this.setAttribute('currenttime', 0);
        </method>
    
        <!---
        Seeks to the given time in milliseconds.
    
        @param number(int) iTimeMs: the time to seek to
        -->
        <method name="seekToTime" args="iTimeMs">
          this.setAttribute('currenttime', Math.floor(iTimeMs));
        </method>
    
        <!-- Private Methods -->
    
    
        <!--- @keywords private -->
        <!---
        Called Internally By Timer
    
        @param number theTime: the actual time in milliseconds that has passed
        since the last timer firing (will usually be 16-100ms more than timer
        firing interval)
        -->
        <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>
    
        <!--- @keywords private -->
        <!---
        Used internally for timer looping.
        -->
        <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>
    
    </library>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can't find the answer to my question in MSND: Does Timer class guarantees that
I was trying to program a Timer class (unaware that boost had one), then
I want a timer class that can post messages to a delegate when there
I have one plain .java class. In that class I'm using a Timer class
I'd like a timer class that allows me to call: .start()   .getElapsedTime()  
I have a timer class set up that is basically handling all of count
i want to build a timer class that inherits from System.Timers.Timer. as so Class
The .NET System.Threading Timer class has several overloaded Change() methods that return true if
I have a problem with the Timer class in that there is a chance
I'm using the System.Timers.Timer class to create a timer with an Timer.Elapsed event. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.