I am in Flex 4 writing actionscript and i already have most of the code for this done here:
Code:import flash.utils.getTimer; [Bindable] private var totalMS:Number = 0; [Bindable] private var startTime:Number; [Bindable] private var stopTime:Number; [Bindable] private var timeDiff:Number; private var watchTimer:Timer; private function init():void { watchTimer = new Timer(100); watchTimer.addEventListener(TimerEvent.TIMER,stopWatchTimerHandler); watchTimer.start(); } private function onStartTimer_CLICK(event:MouseEvent):void { startTime = totalMS; startStopWatch(); } private function onStopTimer_CLICK(event:MouseEvent):void { stopTime = totalMS; timeDiff = stopTime - startTime; } private function startStopWatch():void { watchTimer.start(); } private function stopWatchTimerHandler(event:TimerEvent):void { var now:Date = new Date(); totalMS = totalMS + 100; var hours=now.hours;// setting time on start var minutes=now.minutes; var seconds=now.seconds; } private function resetTimer(event:MouseEvent):void { watchTimer.stop(); startTime = 0; stopTime = 0; timeDiff = 0; totalMS = 0; } private function dateTimer(event:MouseEvent):void { var now:Date = new Date();// getting date startTime = 0; stopTime = 0; timeDiff = 0; totalMS = 0; } private function formatTime(militime:uint):String { var formattedTime:String; var hrs:uint; var mins:uint; var secs:uint; var ms:uint; var msAfterHrs:uint = militime % ((1000 * 60) * 60); var msAfterMins:uint = msAfterHrs % (1000 * 60); var msAfterSecs:uint = msAfterMins % 1000; hrs = (militime - msAfterHrs) / ((1000 * 60) * 60); mins = (msAfterHrs - msAfterMins) / (1000 * 60); secs = (msAfterMins - msAfterSecs) / 1000; ms = msAfterSecs; formattedTime = formatNumber(hrs, 2)+" : "+formatNumber(mins, 2)+" : "+formatNumber(secs, 2)+" : "+formatNumber(ms, 3) ; return formattedTime; } private function formatNumber($num:uint, $digits:uint):String { var formattedNum:String; if ($digits == 2) { if ($num < 10) { formattedNum = "0"+$num; } else { formattedNum = String($num); } } else if ($digits == 3) { if ($num < 10) { formattedNum = "0"+$num; } else if ($num < 100) { formattedNum = "0"+$num; } else { formattedNum = String($num); } } return formattedNum; }
Basically what i need this to do is display a working digital clock with the current time with miliseconds in a format like this:
18 : 30 : 10 : 28
Then i want to be able to have a button that when pressed will record the time and info from other text boxes and save it for later reference. Right now all it deos is count. I really need it to at least display the current time then count. Thanks for you help.




Reply With Quote
