Flex and flash timer setTimeout & setinterval usage points

Source: Internet
Author: User

Reprinted: http://flex4jiaocheng.com/blog/325

You should be familiar with the setTimeout method, and the setinterval method is usually used less frequently. In fact, both of them are very useful "timers", the difference is as follows:

SetTimeout (function, Int, null): uint

It suspends the int ms before executing the function, and the function is executed only once.

Setinterval (function, Int, null): uint

It will pause the function execution after int milliseconds, pause the function execution after int milliseconds again, and then pause the function execution after int milliseconds again ...... (I think you understand what I mean, haha ~~)

So the question is, how can we stop the setinterval method? What's the purpose of returning a uint? The "key" of this article is here.

In fact, we usually only use the setTimeout and setinterval methods, but seldom remember to call the cleartimeout and clearinterval methods to remove the listener added to the program by the set method. This is also a cause of memory vulnerabilities, their usage is as follows:

Cleartimeout (uint): void

It finds the corresponding time listener through the uint (ID of setTimeout) returned by setTimeout, and removes her.

Clearinterval (uint): void

It finds the corresponding time listener through the uint (setinterval ID) returned by setinterval and removes her. This will stop the infinite loop of setinterval.

You must remember to call the cleartimeout and clearinterval methods after using the setTimeout and setinterval methods !!

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.