5 Replies Latest reply on Feb 20, 2011 4:36 AM by Ned Murphy

    Another countdown timer issue.  Not sure why

    aandjmom Level 1

      Hello everyone,

       

      I notice on my 30 minute countdown timer that the seconds seem to skip and/or hesitate at different intervals.  It seems to run for the full 30 minutes but it will be shown on a HUGE screen and the seconds movements is very obvious.  Would someone please show me how to fix the code for complete accuracy in the timing?  Not sure if I should add milliseconds.  ( I dont want that to show in the timer though, just minutes and seconds 00:00.  Thanks in advance.

       

      Here's the code

       

      totalTime = 1800;

      //Start from 30 minute

      startTime = getTimer();

      function timer() {

          timeLeft = (totalTime*1000)-(getTimer()-startTime);

          seconds = Math.floor(timeLeft/1000);

          minutes = 0;

          while (seconds>59) {

              seconds = seconds-60;

              minutes = minutes+1;

          }

          if (minutes<10) {

              minutes = String("0"+minutes);

          }

          if (seconds<10) {

              seconds = String("0"+seconds);

          }

          time_text.text = minutes+" : "+seconds;

          if (timeLeft<=0) {

              time_text.text = ("00:00");

              _root.gotoAndPlay(11);

              clearInterval(timer1);

          }

      }

      timer1 = setInterval(timer, 1000);

       

        • 1. Re: Another countdown timer issue.  Not sure why
          Ned Murphy Adobe Community Professional & MVP

          You are walking a thin line by using an interval of 1 second.  Increase your sampling rate and you are less likely to skip a value.  Here's an approach that samples at the frame rate of the file.  NOte that "var" has been addded in numerous places.  You should always declare your variables regardless that AS2 allows one to not have to.

           

          var totalTime = 1800;

           

          //Start from 30 minute

          var startTime = getTimer();

           

          this.onEnterFrame = function(){

           
              var timeLeft = (totalTime*1000)-(getTimer()-startTime);

              var seconds = Math.floor(timeLeft/1000);

           

              var minutes = Math.floor(seconds/60);

           

              seconds = seconds%60;

           

              if (minutes<10) {
                  minutes = String("0"+minutes);
              }

           

              if (seconds<10) {
                  seconds = String("0"+seconds);
              }

           

              time_text.text = minutes+" : "+seconds;

           

              if (timeLeft<=0) {
                  delete this.onEnterFrame;
                  time_text.text = ("00:00");
                  _root.gotoAndPlay(11);
              }
          }

          • 2. Re: Another countdown timer issue.  Not sure why
            aandjmom Level 1

            NED YOU ARE MY HERO!

             

            I tried you  fix and it works perfectly!

             

            As you can tell i am a total Newbie, and  had no idea  why it worked that way.

             

             

            Thank you a thousand times!!!!!!!!!!!!!!!!!!!!!!!!!

            • 4. Re: Another countdown timer issue.  Highest depth
              aandjmom Level 1

              Another Noob question about this crazy timer.

               

              It is one of  6 levels

               

              I finally got the motion background  seamless but I had to add my second layer ( the church) inside another movie clip to get it on top of th emotion loop.  But now mycountdown timer (althoug I know it works) Is not showing,  I think the depth is wrong,  but since it is a dynamic text and not a movie clip, Im not sure how to get it so be at the highest level.

               

              Here's the codes

               

              var s1 = attachMovie("churchmov_mc", "churchmov_01", 2);

              s1._x = 10;

              s1._y = 100;  To get the  static picture above the movie sky  and

               

               

              var s2 = attachMovie("serve_mc", "serve_mc_01", 5);

              s2._x = 560;

              s2._y = 600;  To get the regular dynamic text above the Static image and the seamless motion sky.

               

              They both work--But my countdown timer ( with  Ned's improvment on my code)   is still underneath it all. ( somewhere)

               

              Please remember I am a total noob, I couldnt even figure out how to force it into a movie clip to manipulate it to "higestdepth"

              AS always,
              Thanks in advance

              • 5. Re: Another countdown timer issue.  Highest depth
                Ned Murphy Adobe Community Professional & MVP

                You could try using the swapDeths method though you may need to place your textfield inside a movieclip

                .

                Another option could be to create empty movieclips on layers below the textfield layer and load (attachMovie) your other content into those movieclips.  That should give them a home anchored in the timeline.

                 

                You should start new postings for new questions for a variety of good reasons... the one on your side is that postings with 0 replies get noticed.  It was only by chance that I checked this one.