Flex timer flash. util. Timer class

Source: Internet
Author: User

The Flash. util. Timer class allows you to call a method by adding a time event or delay. Create an Instance Object using the timer constructor and pass a millisecond number as the construction parameter as the interval. The following example instantiate a timer object to send an event signal every one second:

var timer.Timer = new Timer(1000); 

Once a timer instance is created, an event listener must be added in the next step to process the event. The timer object sends a falsh. event. timerevent event, which is scheduled Based on the set interval or delay time. The following code defines an event listener and calls the ontimer () method as a processing function:

timer.addEventListener(TimerEvent.TIMER,onTimer);
 private function onTimer(event:TimerEvent):void{     trace("on timer"); } 

The timer object does not start automatically. You must call the START () method to start it:

timer.start();

By default, only the stop () method is called to stop. However, another method is to pass the second parameter to the constructor as the number of running times. The default value is 0, which is unlimited, the following example sets the timer to run five times:

var timer:Timer = new Timer(1000, 5); 

The following code sets the timer latency of 5 seconds to execute the deferredmethod () method:

var timer:Timer = new Timer(5000, 1); timer.addEventListener(TimerEvent.TIMER, deferredMethod); timer.start(); 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.