actionscript 实现倒记时代码是安秒计算的;如果是耗秒把小时换算那里修改掉

package 

{

	import flash.display.MovieClip;

	import flash.display.SimpleButton;

	import flash.events.Event;

	import flash.events.MouseEvent;

	import flash.events.TimerEvent;

	import flash.text.TextField;

	import flash.utils.Timer;

	

	public class TimeCounter extends MovieClip

	{

		private var timer:Timer;

		private var timeLabel:TextField;

		/**

		 * 剩余时间,毫秒单位 

		 */		

		private var leftTime:Number;

		

		/**

		 * 时间到之后显示替代文本 

		 */		

		private static const TIME_UP:String = "时间到";

		

		/**

		 * 结束时间,毫秒单位

		 */

		private var _endTime:Number; 

		public function TimeCounter()

		{

			leftTime = 4000; 

			timer = new Timer(1000,leftTime);

			timer.addEventListener(TimerEvent.TIMER,onTimer);

			if(!timeLabel)

			{

				timeLabel = new TextField();

				addChild(timeLabel);

			}			

			timer.start();			

		}

		

		 

		private function onTimer(evt:TimerEvent):void

		{			

			if(leftTime <= 0)

			{

				//到时间了

				timer.stop();

				dispatchEvent(new Event("timeUp"));

			}

			updateTimeLabel(); 

			leftTime --;

		}

		

		private function updateTimeLabel():void

		{

			if(leftTime <= 0) 

			{

				timeLabel.text = TimeCounter.TIME_UP;

				return;

			}

			var h:Number = Math.floor(leftTime / (60 * 60) );

			var m:Number = Math.floor(leftTime % (60 * 60) / (60));

			var s:Number = Math.floor(leftTime % (60));

			

			

			timeLabel.text = oneToTow(h) + " 小时 " + oneToTow(m) + " 分 " + oneToTow(s) + "秒";

			trace(timeLabel.text);

		}

		

		private function oneToTow(value:Number):String

		{

			var str:String;

			if(value < 10)

			{

				str = "0" + value;

			}

			else

			{

				str = "" + value;

			}

			return str;

			

		}

	}

}

  

你可能感兴趣的:(actionscript)