5 Replies Latest reply on Jun 9, 2009 10:45 AM by donverse_r

    Flash question (if / else)

    donverse_r

      Hey guys,

       

      I just found a video tutorial online that was kinda helpful for my homepage.

      I want to change one thing though, (and tried for the last 2 hours) but I don't really (or at all) get it to work how I want it.

       

      http://www.republicofcode.com/tutorials/flash/video/countdown.php

       

      This is the tutorial and it creates a countdown timer in flash.

      Following the Actionscript, what I want to accomplish is that the timer actually stops after the event has happened and displays some kind of a text.

      I tried playing around with an if statement (the last line), something like

       

       

      
      if (counter > 0) {
      
           time_txt.text = counter;
      
      } else {
      
           time_txt.text = "Random Text";
      
      }
      

       

      but that did not work for me, and I honestly don't know why.

      Attached the entire Actionscript if somebody wants to help me.

      Thanks in advance.

       

      Don

       

      this.onEnterFrame = function()    {
          var today:Date = new Date();
          var currentYear = today.getFullYear();
          var currentTime = today.getTime();
          
          var targetDate:Date = new Date(2009,5,27);
          var targetTime = targetDate.getTime();
          
          var timeLeft = targetTime - currentTime;
          
          var sec = Math.floor(timeLeft/1000);
          var min = Math.floor(sec/60);
          var hrs = Math.floor(min/60);
          var days = Math.floor(hrs/24);
          sec = string(sec % 60);
          if (sec.length < 2) {
              sec = "0" + sec;
          }
          min = string(min % 60);
          if (min.length < 2) {
              min = "0" + min;
          }
          hrs = string(hrs % 24);
          if (hrs.length < 2) {
              hrs = "0" + hrs;
          }
          days = string(days);
          
          var counter:String = days + " : " + hrs + " : " + min + " : " + sec;    
          time_txt.text = counter;    
      }
      
        • 1. Re: Flash question (if / else)
          kglad Adobe Community Professional & MVP

          :

           

          this.onEnterFrame = function() {
             
              var today:Date = new Date();
              var currentYear = today.getFullYear();
              var currentTime = today.getTime();
              var targetDate:Date = new Date(2009, 5, 27);
              var targetTime = targetDate.getTime();
              var timeLeft = targetTime-currentTime;
              if(timeLeft==0{
                 delete this.onEnterFrame;
                 time_txt.text="random text";
                 } else {
              var sec = Math.floor(timeLeft/1000);
              var min = Math.floor(sec/60);
              var hrs = Math.floor(min/60);
              var days = Math.floor(hrs/24);
              sec = String(sec%60);
              if (sec.length<2) {
                  sec = "0"+sec;
              }
              min = String(min%60);
              if (min.length<2) {
                  min = "0"+min;
              }
              hrs = String(hrs%24);
              if (hrs.length<2) {
                  hrs = "0"+hrs;
              }
              days = String(days);
              var counter:String = days+" : "+hrs+" : "+min+" : "+sec;
              time_txt.text = counter;
              }
          };

          1 person found this helpful
          • 2. Re: Flash question (if / else)
            donverse_r Level 1

            Thanks for the try, but if I plug in a date that's in the past it's still showing me -x days left.

             

            Anyone else?

             

            Don

            • 3. Re: Flash question (if / else)
              Ned Murphy Adobe Community Professional & MVP

              If you change the comparison operator in this one line in what kGlad provided it will probably work for a past date/time...

               

              if(timeLeft==0{

              1 person found this helpful
              • 4. Re: Flash question (if / else)
                kglad Adobe Community Professional & MVP

                kglad wrote:

                 

                :

                 

                this.onEnterFrame = function() {
                   
                    var today:Date = new Date();
                    var currentYear = today.getFullYear();
                    var currentTime = today.getTime();
                    var targetDate:Date = new Date(2009, 5, 27);
                    var targetTime = targetDate.getTime();
                    var timeLeft = targetTime-currentTime;
                    if(timeLeft<=0){
                       delete this.onEnterFrame;
                       time_txt.text="random text";
                       } else {
                    var sec = Math.floor(timeLeft/1000);
                    var min = Math.floor(sec/60);
                    var hrs = Math.floor(min/60);
                    var days = Math.floor(hrs/24);
                    sec = String(sec%60);
                    if (sec.length<2) {
                        sec = "0"+sec;
                    }
                    min = String(min%60);
                    if (min.length<2) {
                        min = "0"+min;
                    }
                    hrs = String(hrs%24);
                    if (hrs.length<2) {
                        hrs = "0"+hrs;
                    }
                    days = String(days);
                    var counter:String = days+" : "+hrs+" : "+min+" : "+sec;
                    time_txt.text = counter;
                    }
                };

                • 5. Re: Flash question (if / else)
                  donverse_r Level 1

                  Oh man, thanks so much

                  You're the best.

                  Thanks to both of you though

                   

                  Don