StephenAdams
StephenAdams

Reputation: 529

calling a function once then repeated at a set interval

I have a function which makes a call to the server to load some financial data. This data is then displayed in a grid. In order to keep displaying the latest data I keep making this server call (every 30 secs). I'm using a Timer object to do this. The problem I have is that I have to wait 30 secs when the application starts for financial data to be displayed, what I'd like to happen is that the load data call is made, then start the update timer. Is there a way to set this up or shall I use to data load calls, one to get the initial data, then one to get the updates, which is made every 30 secs?

Thanks

Stephen

Upvotes: 1

Views: 615

Answers (1)

Borek Bernard
Borek Bernard

Reputation: 53331

You will have a code like this:

timer = new Timer(30000);
timer.addEventListener(TimerEvent.TIMER, function(e:TimerEvent):void {
    loadData();
});
timer.start();

so just change it to

timer = new Timer(30000);
timer.addEventListener(TimerEvent.TIMER, function(e:TimerEvent):void {
    loadData();
});
loadData();
timer.start();

Note the call to loadData() before timer.start().

Upvotes: 1

Related Questions