Flex倒计时 可以用但还有点小问题

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
				creationComplete="application1_creationCompleteHandler(event)"
				layout="absolute">

	<mx:Script>
		<![CDATA[
			/**
			 *
			 * Flex倒计时
			 *
			 * */

			import mx.events.FlexEvent;
			[Bindable]
			public var str:String;
			public var timer:Timer;

			private var isStop:Boolean=false;

			protected function application1_creationCompleteHandler(event:FlexEvent):void
			{
				// TODO Auto-generated method stub
				timer=new Timer(1000);
				timer.addEventListener(TimerEvent.TIMER, timehandle);

			}

			private function startTimer():void
			{
				timer.start();
			}

			private function stopTimer():void
			{
				timer.stop();
			}

			private function timeTransform(stattime:int, counter:int):String
			{
				var str:String="";
				var count:int=stattime - counter;
				var hour:int=Math.floor(count / 3600);
				var miniter:int=count % 3600 / 60;
				var second:int=count % 60;
				str=(hour < 10 ? "0" + hour : hour) + ":" + (miniter < 10 ? "0" + miniter : miniter) + ":" + (second < 10 ? "0" + second : second) + "";

				if (hour == 0 && miniter == 0 && second == 0)
				{
					isStop=true;
				}
				else
				{
					isStop=false;
				}

				return str;
			}

			private function timehandle(e:TimerEvent):void
			{
				var count:int=timer.currentCount;
				str=timeTransform(30, count);
				if (isStop)
				{
					stopTimer();
				}
				trace(str);
			}
		]]>
	</mx:Script>
	<mx:Label x="65"
			  y="108"
			  width="311"
			  height="62"
			  fontSize="50"
			  text="{str}"/>
	<mx:Button x="70"
			   y="17"
			   label="开始"
			   click="startTimer()"/>
	<mx:Button x="174"
			   y="17"
			   label="暂停"
			   click="stopTimer()"/>

</mx:Application>

猜你喜欢

转载自oywl2008.iteye.com/blog/2214509