Using Flex; How to get server time and keep increasing without calls for every second

I am working on an application where server time should be displayed in a Flex application. The idea is to make a remote call to BlazeDS getServerTime () once during the intuition of the application and then use the local Timer class to update the display. (I don't want to bombard the server with getServerTime () for every second).

My question is when do I have an AS3 Date object. How to increase it in a few seconds?

//remoteServerDateTime value is already set by a remote blazeds call
[Bindable] 
var serverTime:Date = remoteServerDateTime;

public function updateTime():void 
{ 
    //I am trying to add code here that increments serverTime by 1 sec.
    serverTime = serverTime + 1 // this wont work




    ticker = new Timer(1,1); 
    ticker.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete); 
    ticker.start(); 
} 

public function onTimerComplete(event:TimerEvent):void{ 
      updateTime(); 
} 

//creationComplete = updateTime();
//MXML <mx:Label text={serverTime} "/>
+3
source share
1 answer

You need to use , not : getTime()getSeconds()

serverTime.setTime(serverTime.getTime() + 1000);

- , . , , , .

ticker.start() x onTimerComplete, onTimerComplete x + 1 , 1 . , serverTime 60 .

( ). , repeatCount 0, .

, . , , . - .

// Initialized when the server responds:
// difference = server time minus local time, in milliseconds
var localToServerDifference:Number =
    remoteServerDateTime.getTime() - new Date().getTime();

public function updateTime():void 
{
    // server time = local time plus difference
    serverTime.setTime(new Date().getTime() + localToServerDifference);
}
+2

All Articles