Flash as 3.0 Novice Learning to fly Tutorial: Three ways to perform the interval cycle

Source: Internet
Author: User
Tags setinterval time interval

Learn AS3 rookie take off.-Interval cycle

If you want the animation to be independent of the frame rate, you can use 3 methods.

1, Setlnterval () function

The function of the Setlnterval () function is to call functions at a certain time

The Setlnterval () function is in the form of:

Setlnterval (functions name, time interval, function parameter);

Function name is the name of the custom function, the time interval is milliseconds, and the parameter is a parameter of the custom function.

Let's make a timer:

//时间的初始值
var t:int;
//定义一个无参函数
function time()
{
//输出时间
 trace(++t / 10);
}
//每隔0.1秒调用一次函数
setInterval(time,100);

Test the above code to see the time increment in 0.1 seconds in the output panel.

Tip: the Setlnterval () function calls a function every 0.1 seconds, and the variable t is incremented by 1, and t divided by 10 to indicate the time.

The following code calls a parameter function:

//定义一个有参函数
function test(message)
{
trace(message);
}
//每隔500毫秒调用一次函数,输出“调用函数”
setInterval(test,500,"调用函数");

Clears the call to SetInterval (), using the Clearinterval () function

Hint: The call to clear the setinterval () function in time will result in a duplicate call to the SetInterval () function.

2, settimeout () function

The settimeout () function is used in the same way as the Setlnterval () function, and it is called at a certain time.

The general form of the settimeout () function is:

settimeout (functions name, time interval, function parameter);

Call a parameterless function:

//自定义函数,输出信息
function test()
{
trace("函数调用");
}
//每隔1000毫秒调用一次test(),输出信息。
setTimeout(test,1000);

Clears the call to SetTimeout () and uses the Cleartimeout () function.

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.