5 Replies Latest reply on Jan 30, 2007 11:26 AM by joener

    timer problem

    joener
      I have a problem with a timer. The timer must count down from 60 to 0, and if I click on a button it must add 10 seconds.

      My timer is now working, but he is not adding 10 seconds if I click on the "+10 seconds" - button.

      You can download my project here

      This is my script:

      quote:

      var timing:Boolean = false;
      var paused:Boolean = false;
      var elapsedTime:Number;
      var elapsedS:Number;
      var elapsed:Number;
      var startTime:Number;
      var starttTime:Number;
      var seconds:String;

      //script for starting button
      _root.start_btn.onPress = function() {
      if(!_root.timing) {
      if (_root.paused) {
      _root.startTime = elapsedTime + getTimer();
      } else {
      _root.startTime = getTimer(); }
      _root.paused = false;
      _root.timing = true; }}

      //script for stop button
      _root.pause_btn.onPress = function() {
      if(_root.timing) {
      _root.timing = false;
      _root.paused = true; }}

      // calculating time
      _root.onEnterFrame = function() {
      if (timing) {
      elapsedTime = startTime - getTimer();
      elapsed = elapsedTime + 60000;
      elapsedS = Math.floor(elapsed / 1000);
      if (elapsedS < 0) {
      seconds = "0";
      } else {
      seconds = elapsedS.toString();
      }
      _root.timer_txt = seconds;}}


      how do I add 10 seconds when I click on a button?
        • 1. Re: timer problem
          joener Level 1
          could somebody plz help me out??

          I have been searching for a week in forums, books, internet, ... and didn't found it.
          • 2. Re: timer problem
            Peter Lorent Level 2
            Adding 10 isn't your main problem. The onEnterFrame will immediately overwrite any addition. In the current code you can only add to the counter if the timer is paused. You need to change the logic if you want to add while the timer is running.
            About adding 10 (or any amount for that matter): you can't add a number to a string value so you need some conversion there.
            • 3. Re: timer problem
              joener Level 1
              damn ...

              and if I add a few variables like this:

              quote:



              _root.10seconds_btn.onPress{
              addtime = addtime + 10000}


              _root.onEnterFrame = function() {
              if (timing) {
              elapsedTime = startTime - getTimer();
              elapsed = elapsedTime + 60000 + addtime;
              elapsedS = Math.floor(elapsed / 1000);
              if (elapsedS < 0) {
              seconds = "0";
              } else {
              seconds = elapsedS.toString();
              }
              _root.timer_txt = seconds;}}



              is that possible??

              Then the variable "addtime" should be 0 in the beginning, and if I click on the button it should add 10 seconds to it.

              Could that be a solution to the problem??
              • 4. Re: timer problem
                Peter Lorent Level 2
                >>is that possible??
                Did you try?
                • 5. Re: timer problem
                  joener Level 1
                  Yes I did.

                  But "addtime + 10000= addtime" doesn't work :(