3 Replies Latest reply: Feb 29, 2012 3:15 PM by Ned Murphy RSS

    How to get this timer to run non stop....

    csclark0530

      I have this count up timer but I need it to run non stop once I put it on a website....here is the code....

       

      var startT:Number = 1;

      var endT:Number =8000000;

      onEnterFrame = function ()

      {

          if (startT >=endT)

          {

              delete onEnterFrame;

              tf.text = String(endT);

          }

          else

          {

              tf.text = String(startT);

              startT += 1;

          }

      }

        • 1. Re: How to get this timer to run non stop....
          Ned Murphy MVP

          If you mean you want to be able to go back to the web site multiple times and see how far along it has continued to count, that won't happen with the approach your code shows unless you leave the file running and hang around for the 8 million counts.  Your code will always start counting at 1. 

           

          What you really need to have is a timer that counts relative to a starting date/time.

          • 2. Re: How to get this timer to run non stop....
            csclark0530 Community Member

            How would I do this? I'm fairly new at this so I'm trying to learn.

            • 3. Re: How to get this timer to run non stop....
              Ned Murphy MVP

              What you would do is select a starting date/time, preferably in the past relative to the date/time you have the file on the web.  Then you take the current date/time and subtract the starting date/time from it.  Then convert that if you need to into some numeric value.

               

              Just as a for instance, look into the getTime() method of the Date class.  It always returns the number of milliseconds from a particular date/time (January 1, 1970).  So you declare a start Date object using the Date constructor (see the help files) and use the getTime() method for that Date to get the starting time.  Then keep looping and creating new Date object for the current date/time and run the getTime() method for that.  Within each loop you subtract the second time from the first to get the time between them (in milliseconds) which you are free to deal with as you prefer in terms of how you convert/present it.  When the desired value has been reached you execute your    tf.text = String(endT); line.