Countdown Timer Clock AS3倒计时组件

<?xml version="1.0" encoding="utf-8"?>

<mx:Label xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">

   <mx:Script>

      <![CDATA[

          /**

       * The Timer that acts like a heartbeat for the application.

       */

       private var ticker:Timer;

         public var countDownDate:Date;

                        

         private function init():void

         {
            // creates a Timer that fires an event once per second
       ticker = new Timer(1000);

       // designates the onTick() method to handle Timer events
       ticker.addEventListener(TimerEvent.TIMER, onTick);

       // starts the clock ticking
       ticker.start();
         }

         

         public function onTick(evt:TimerEvent):void

       {

          

       // updates the clock display
            this.text = getCountDown(countDownDate.getTime() - (new Date()).getTime());

       }

    protected function getCountDown(uptime:Number):String

    {
       //current date
       var currentDate:Date
            
            // get current Date
            currentDate = new Date();
            
            //initialize event variables. Seconds are using Math().
            var eventMonth:int = 8; //Sept = 8
            var eventDay:int = 29;
            var eventHours:int = 8;
            var eventMinutes:int = 0;
            
            //get time zone offset. Number returned in minutes.
            var currentOffset:Number = currentDate.getTimezoneOffset();
            
            //check if we started
       if(uptime <= 0) return "MAX has begun!";

            var secs:Number = uptime/1000;

// Construct String
            var result:String = new String();
            
            // For debug only...
            //result += "Current UTC date is: " + currentDate + ". MAX 2007 is ";
            
            // Build Result string
            result += "MAX 2007 begins in ";

/*How many months until MAX 2007*/
            var months2MAX:int =
            eventMonth - currentDate.getMonth();
            result += months2MAX + " Months ";

/*How many days until max*/
            var days2MAX:int = eventDay - currentDate.getDate();
          result += days2MAX + " Days " ;            
            
            /* How many hours including the offset from users local time*/
            var hours2MAX:int = (eventHours + (currentOffset/60)) - currentDate.getHours();
            result += hours2MAX + ":";
         
            var minutes2MAX:int = (60 - currentDate.getMinutes());
            result += minutes2MAX + ":";
       
       result += (60 - currentDate.getSeconds());

       return result;
    }
      ]]>

   </mx:Script>

</mx:Label>

Share

0 条评论

留下评论