A simple flex application for the implementation of the Timer, which can have buttons for Start, Pause and Reset.
Program:-
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontWeight="bold"> <mx:Script> <![CDATA[ [Bindable] private var second:Number=0; [Bindable] private var minute:Number=0; [Bindable] private var hour:Number=0; private var timer:Timer = new Timer(10); public var cnt:int = 1; private function init():void { timer.addEventListener(TimerEvent.TIMER, my_timer_timer); timer.start(); lbl1.text = "1"; } private function my_timer_timer(evt:TimerEvent):void { second = int(lbl1.text); txt_display.text = hour+':'+ minute+':'+second; second++; lbl1.text = String(second); if(second>59) { minute++; second = 0; lbl1.text = String(second); if(minute>59) { hour++; minute=0; second =0; lbl1.text = String(second); } } } private function pause():void { timer.stop(); txt_display.text = hour+':'+ minute+':'+second; } private function reset():void { minute=0; hour=0; second=0; txt_display.text = hour+':'+ minute+':'+second; } ]]> </mx:Script> <mx:Panel width="275" height="305" layout="absolute" borderColor="#000000" title="TIMER" horizontalCenter="19" verticalCenter="8.5"> <mx:Label id="lbl1" enabled="false"/> <mx:Button x="20.5" y="176" label="Start" id="btn_start" click="{init()}" fillColors="[#8080ff, #b3f4f4]"/> <mx:TextInput x="32.5" y="102" height="35" width="190" id="txt_display" fontSize="22" textAlign="center"/> <mx:Button x="97" y="176" label="Pause" id="btn_pause" click="{pause()}" fillColors="[#8080ff, #b3f4f4]"/> <mx:Button x="186" y="176" label="Reset" id="btn_reset" click="{reset()}" fillColors="[#8080ff, #b3f4f4]"/> </mx:Panel> </mx:Application> |
Screen Shot:-










