call a function after few seconds using the method setTimeout().

In a Flex app if you want to call a function after sometime (in seconds or hours) you can use the method setTimeout().The below def shows the use.

setTimeout(getmyName,3000);

Here the method setTimeout() calls the function getmyName after 3 sec in the execution flow.i.e when the line setTimeout reaches in the excution flow then the execution flow calls the function getmyName after 3 sec as mentioned in the method.

The below code example explains the need.

import mx.managers.PopUpManager;
import flash.utils.setTimeout;
import mx.controls.Alert;
private var alert:Alert;
private function init():void
{
alert=Alert.show(“Hai”,”Kumar”);
setTimeout(hidealert,3000);
}
private function hidealert():void
{
PopUpManager.removePopUp(alert);
}

Here the function init() is called at creationComplete of the app.And it alerts and then waits for 3 sec and closes the Alert window as we are using the setTimeout method and calling a function to close the Alert using the PopUpManager class.

The method setTimeout() can used as our need in the app.leave any comments for suggestions.

Advertisements

One Response to call a function after few seconds using the method setTimeout().

  1. Saniyan says:

    Dubukku

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: