Using Timer Class in Flex.

Using Timer Class we can raise an Event at specified Time and even at the completion of the specified Time.

The below example uses two events, one if fired for every sec and other one after the completion of the Time specified.First define a var of type Timer with time specified ,which specifies the time interval you wanted to raise the event.

var mTimer:Timer=new Timer(1000,5);//ticks for 5 sec’s

Then add events to it for every sec and completion of specified time like below.

mTimer.addEventListener(TimerEvent.TIMER,Countsec);
mTimer.addEventListener(TimerEvent.TIMER_COMPLETE,Comple);

Now start time.

mTimer.start();

Define the two function you wanted to call for events.like below.

private function Countsec(e:TimerEvent):void
{
lbltime.text=e.target.currentCount;
}
private function Comple(e:TimerEvent):void
{
lbltime.text=”Time Complete”;
}

Here lblTime is the Label Control id in Flex.

<mx:Label id=”lbltime” x=”374″ y=”167″ width=”369″ height=”61″ fontWeight=”bold” fontSize=”30″/>

Thats all the Time is set for 5 sec, Enjoy the code. 

Advertisements

5 Responses to Using Timer Class in Flex.

  1. Martin says:

    nice ticket…simple and it works fine 🙂

  2. arthipesa says:

    saviour code, 🙂 thank you bro..

  3. Thank you, its great for beginners

    Thank you

  4. Ragu says:

    Really super and simple.

    Thanks

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: