<?xml version="1.0" encoding="utf-8"?> <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="486" height="82" creationComplete="init()" fontWeight="bold"> <fx:Script> <![CDATA[ import flash.events.Event; import flash.events.TimerEvent; import flash.media.Sound; import flash.media.SoundChannel; import flash.utils.Timer; import mx.controls.Alert; import mx.events.CloseEvent; import mx.events.ColorPickerEvent; private var timer:Timer; public var h_num:int=0; public var m_num:int=0; public var s_num:int=10; public var sumit:Function; private function init():void { this.timeComplete(); timer = new Timer(1000, 0); timer.addEventListener(TimerEvent.TIMER, onTimer); timer.start(); } private function onTimer(event:TimerEvent):void { s_num = s_num - 1; if ((s_num == -1) && (m_num > 0)) { m_num = m_num - 1; s_num = 59; } if ((m_num == 0) && (h_num > 0)) { h_num = h_num -1; m_num = 59; s_num = 59; } if(s_num<30 && h_num==0 && m_num==0){ tip.text="距离考试结束还有"+s_num+"秒,请您尽快提交当前题的答案哦!"; } if (s_num < 0) { s_num = 0; timer.stop(); Alert.yesLabel = "确定"; Alert.show("考试结束时间到!", "提示", Alert.YES, this, function(event:CloseEvent):void{ var flag:int = event.detail; if(flag == Alert.YES){ Alert.show("YES"); //sumit.call(); } }); } var hh:String; var mm:String; var ss:String; hh = (h_num < 10) ? "0" + h_num.toString() : h_num.toString(); mm = (m_num < 10) ? "0" + m_num.toString() : m_num.toString(); ss = (s_num < 10) ? "0" + s_num.toString() : s_num.toString(); time2_txt.text = time_txt.text = hh + "小时" + mm + "分" + ss+"秒"; } private function timeComplete():void { var hh:String; var mm:String; var ss:String; hh = (h_num < 10) ? "0" + h_num.toString() : h_num.toString(); mm = (m_num < 10) ? "0" + m_num.toString() : m_num.toString(); ss = (s_num < 10) ? "0" + s_num.toString() : s_num.toString(); time2_txt.text = time_txt.text = hh + ":" + mm + ":" + ss; } ]]> </fx:Script> <fx:Declarations> <mx:RadioButtonGroup id="colorSel" /> </fx:Declarations> <mx:Text id="time2_txt" x="211" y="5" width="273" height="45" color="#9CF5D7" fontSize="30" fontWeight="bold"/> <mx:Text id="time_txt" width="275" height="44" fontSize="30" color="#BE03FC" fontWeight="bold" x="208" y="3"/> <s:Label x="10" y="15" width="199" height="32" color="#FBE703" fontFamily="中易黑体" fontSize="22" fontWeight="bold" text="距离考试结束还有:"/> <s:Label x="24" y="51" width="439" height="22" color="#FD0303" fontSize="16" id="tip"/> </s:Group>
转载于:https://www.cnblogs.com/hekin/archive/2012/07/18/2597011.html