I am trying to use timer in flex. I referred to this example : Timer : blog.flexexamples.com
.
Here is what I want to achieve:
I want to start the timer, showing minutes elapsed since timer started. It should be independent of the region you are in.( irrespective of whatever zone you are in, timer should work fine in every zone).
Timer should continue, unless some button is clicked, where I want to show the time elapsed in minutes, in an Alert Box and then timer should start again from 0 onwards.
I tried my example, but it is not working properly.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
creationComplete="init()">
<mx:Script>
<![CDATA[
import flash.events.TimerEvent;
import flash.utils.Timer;
import mx.controls.Alert;
private const TIMER_INTERVAL:Number = 10;
private var baseTimer:int;
private var t:Timer;
private function init():void {
t = new Timer(TIMER_INTERVAL);
t.addEventListener(TimerEvent.TIMER, updateTimer);
}
private function updateTimer(evt:TimerEvent):void {
var d:Date = new Date(getTimer()-baseTimer);
var min:String = (d.minutes).toString();
var sec:String = (d.seconds).toString();
counter.text = String(min+"."+sec);
}
private function startTimer():void {
baseTimer = getTimer();
t.start();
}
private function stopTimer():void {
t.stop();
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:Button label="Start timer" click="startTimer()" />
<mx:Button label="Stop timer" click="stopTimer()" />
</mx:ApplicationControlBar>
<mx:Label id="counter" fontSize="96" />
</mx:Application>
Can somebody tell what is the problem ? How to solve it ?
EDIT : If I run this example on my pc, timer starts from 30.0 till it reaches 59.59 and then it turns back to 0.0 and then starts again......Now What I want is to start from 0.0 and continue counting minutes till some button is clicked ... and this should work in any time zones