1 Reply Latest reply on Sep 21, 2008 5:20 AM by Newsgroup_User

    Start/Stop Timer

    Bike Racer
      I have this countdown timer, but would like to be able to start/pause it by means of a button. Anyone willing to offer a suggestion?
        • 1. Re: Start/Stop Timer
          Level 7
          You just need your button to modify a flag variable, and then have the
          enterFrame check it first:

          start_time = getTimer();
          paused = false;
          countdown=720000;
          onEnterFrame = function () {
          elapsed_time = getTimer()-start_time;
          if(!paused){
          _root.count_down.text =
          time_to_string(_root.countdown-elapsed_time);
          }
          };
          function time_to_string(time_to_convert) {
          elapsed_hours = Math.floor(time_to_convert/3600000);
          remaining = time_to_convert-(elapsed_hours*3600000);
          elapsed_minutes = Math.floor(remaining/60000);
          remaining = remaining-(elapsed_minutes*60000);
          elapsed_seconds = Math.floor(remaining/1000);
          remaining = remaining-(elapsed_seconds*1000);
          elapsed_fs = Math.floor(remaining/10);
          if (elapsed_hours<10) {
          hours = "0"+elapsed_hours.toString();
          } else {
          hours = elapsed_hours.toString();
          }
          if (elapsed_minutes<10) {
          minutes = "0"+elapsed_minutes.toString();
          } else {
          minutes = elapsed_minutes.toString();
          }
          if (elapsed_seconds<10) {
          seconds = "0"+elapsed_seconds.toString();
          } else {
          seconds = elapsed_seconds.toString();
          }
          if (elapsed_fs<10) {
          hundredths = "0"+elapsed_fs.toString();
          } else {
          hundredths = elapsed_fs.toString();
          }
          return minutes+":"+seconds;
          }
          pauseButton.onRelease = function(){
          paused = !paused;
          }

          --
          Dave -
          www.offroadfire.com
          Head Developer
          http://www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/