5 Replies Latest reply on Mar 17, 2011 3:39 PM by Ned Murphy

    Countdown Timer

    adzaus
      Hi,

       

      just want to know if some one can help me with my countdown timer.

       

      every time it gets to zero it goes back to 59:59:59:59.

       

      i need it to stay at 00:00:00:00 or even better make it flash.

       

      var thisYear:Number = 2011;
      var thisDay:Number = 28;
      var thisMonth:Number = 2;
      var thisHours:Number = 19;
      var thisMin:Number = 30;
      var thisSec:Number = 0;
      var countdownXML:XML = new XML();
      countdownXML.ignoreWhite = true;
      countdownXML.load( 'countdown.xml' );
      countdownXML.onLoad = function( success:Boolean ):Void

      var nowDate:Date = new Date();
      if( success ) {
           var eventDateData = countdownXML.childNodes[0].childNodes;
        if( eventDateData[0].attributes['year'] ) thisYear = Number( eventDateData[0].attributes['year'] );
        if( eventDateData[0].attributes['month'] ) thisMonth = Number( eventDateData[0].attributes['month'] );
        if( eventDateData[0].attributes['day'] ) thisDay = Number( eventDateData[0].attributes['day'] );
        if( eventDateData[0].attributes['hours'] ) thisHours = Number( eventDateData[0].attributes['hours'] );
        if( eventDateData[0].attributes['minutes'] ) thisMin = Number( eventDateData[0].attributes['minutes'] );
        if( eventDateData[0].attributes['seconds'] ) thisSec = Number( eventDateData[0].attributes['seconds'] );
       
        var testEventDate = new Date(thisYear, thisMonth-1, thisDay, thisHours, thisMin, thisSec );
        if( testEventDate <= nowDate ) {
         thisYear = nowDate.getUTCFullYear();
         thisDay = nowDate.getUTCDate() + Math.round( Math.random() );
         thisMonth = nowDate.getUTCMonth();
         thisHours = nowDate.getHours();
         thisMin = nowDate.getMinutes();
         thisSec = nowDate.getSeconds();
        }
      } else {
        thisYear = nowDate.getUTCFullYear();
        thisDay = nowDate.getUTCDate();
        thisMonth = nowDate.getUTCMonth();
        thisHours = nowDate.getHours();
        thisMin = nowDate.getMinutes();
        thisSec = nowDate.getSeconds();
      }
      startCountdown();
      }
      function startCountdown():Void
      {
      eventDate = new Date(thisYear, thisMonth-1, thisDay, thisHours, thisMin, thisSec );
      this.onEnterFrame = update;
      }
      function update():Void
      {
      //Current time
      var now:Date = new Date();
      var timeLeft:Number = eventDate.getTime() - now.getTime();

      //Converting the remaining time into seconds, minutes, hours, and days
      var seconds:Number = Math.floor(timeLeft / 1000);
      var minutes:Number = Math.floor(seconds / 60);
      var hours:Number = Math.floor(minutes / 60);
      var days:Number = Math.floor(hours / 24);

      //Storing the remainder of this division problem
      seconds %= 60;
      minutes %= 60;
      hours %= 24;
      updateCounters( days, hours, minutes, seconds );
      }
      function updateCounters( numDays, numHours, numMin, numSec ):Void
      {
      days.gotoAndPlay( 'to' + numDays );
      hours.gotoAndPlay( 'to' + numHours );
      min.gotoAndPlay( 'to' + numMin );
      sec.gotoAndPlay( 'to' + numSec );
      }

       

      if some could help that would be great.

       

      Regards,

       

      Adam

       

       

       

        • 1. Re: Countdown Timer
          Ned Murphy Adobe Community Professional & MVP

          You could try adding a conditional after you call the updateCounters function in your update function...

           

          updateCounters( days, hours, minutes, seconds );
          if(days == 0 && hours == 0 && minutes == 0 and seconds == 0){

                 delete this.onEnterFrame;

          }

          • 2. Re: Countdown Timer
            adzaus Level 1

            is this where abouts i should be putting it becuase i am still having the same problem

             

            // first get this current year so this example

            // remains valid for some time to come

            var thisYear:Number = 2011;

            var thisDay:Number = 28;

            var thisMonth:Number = 2;

            var thisHours:Number = 19;

            var thisMin:Number = 30;

            var thisSec:Number = 0;

            var countdownXML:XML = new XML();

            countdownXML.ignoreWhite = true;

            countdownXML.load( 'countdown.xml' );

            countdownXML.onLoad = function( success:Boolean ):Void

            var nowDate:Date = new Date();

            if( success ) {

                 var eventDateData = countdownXML.childNodes[0].childNodes;

              if( eventDateData[0].attributes['year'] ) thisYear = Number( eventDateData[0].attributes['year'] );

              if( eventDateData[0].attributes['month'] ) thisMonth = Number( eventDateData[0].attributes['month'] );

              if( eventDateData[0].attributes['day'] ) thisDay = Number( eventDateData[0].attributes['day'] );

              if( eventDateData[0].attributes['hours'] ) thisHours = Number( eventDateData[0].attributes['hours'] );

              if( eventDateData[0].attributes['minutes'] ) thisMin = Number( eventDateData[0].attributes['minutes'] );

              if( eventDateData[0].attributes['seconds'] ) thisSec = Number( eventDateData[0].attributes['seconds'] );

               

              var testEventDate = new Date(thisYear, thisMonth-1, thisDay, thisHours, thisMin, thisSec );

              if( testEventDate <= nowDate ) {

               thisYear = nowDate.getUTCFullYear();

               thisDay = nowDate.getUTCDate() + Math.round( Math.random());

               thisMonth = nowDate.getUTCMonth();

               thisHours = nowDate.getHours();

               thisMin = nowDate.getMinutes();

               thisSec = nowDate.getSeconds();

              }

            } else {

              thisYear = nowDate.getUTCFullYear();

              thisDay = nowDate.getUTCDate() + 30;

              thisMonth = nowDate.getUTCMonth() + 1;

              thisHours = nowDate.getHours();

              thisMin = nowDate.getMinutes();

              thisSec = nowDate.getSeconds();

            }

            startCountdown();

            }

            function startCountdown():Void

            {

            eventDate = new Date(thisYear, thisMonth-1, thisDay, thisHours, thisMin, thisSec );

            this.onEnterFrame = update;

            }

            function update():Void

            {

            //Current time

            var now:Date = new Date();

            var timeLeft:Number = eventDate.getTime() - now.getTime();

             

            //Converting the remaining time into seconds, minutes, hours, and days

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

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

            var hours:Number = Math.floor(minutes / 60);

            var days:Number = Math.floor(hours / 24);

             

            //Storing the remainder of this division problem

            seconds %= 60;

            minutes %= 60;

            hours %= 24;

            updateCounters( days, hours, minutes, seconds );

            if(days == 0 && hours == 0 && minutes == 0 and seconds == 0){      

            delete this.onEnterFrame;}

            }

            function updateCounters( numDays, numHours, numMin, numSec ):Void

            {

            days.gotoAndPlay( 'to' + numDays );

            hours.gotoAndPlay( 'to' + numHours );

            min.gotoAndPlay( 'to' + numMin );

            sec.gotoAndPlay( 'to' + numSec );

            }

             

            Date: Wed, 16 Mar 2011 20:27:52 -0600

            From: forums@adobe.com

            To: a_ollerton@live.com.au

            Subject: Countdown Timer

             

            You could try adding a conditional after you call the updateCounters function in your update function...

             

            updateCounters( days, hours, minutes, seconds );

            if(days == 0 && hours == 0 && minutes == 0 and seconds == 0){

                   delete this.onEnterFrame;

            }

            >

            • 3. Re: Countdown Timer
              Ned Murphy Adobe Community Professional & MVP

              Yep.  Maybe the problem lies in whatever you are doing with the counters.

              1 person found this helpful
              • 4. Re: Countdown Timer
                adzaus Level 1

                oh ok. would i be able to send you a zip folder that containes the .fla and .xml files if so please send me a email to a_ollerton@live.com.au. i have been trying to fix this for a while.

                 

                Or

                 

                Should i tell it to load a photo when it reaches zero.

                • 5. Re: Countdown Timer
                  Ned Murphy Adobe Community Professional & MVP

                  You should look into what is happening with the counters.  How are those designed?  What would they be playing when they gotoAndPlay("to"+...)?  If they only go to a particular frame, and don't really play anything, then maybe you should try using gotoAndStop(...) instead

                  1 person found this helpful