1、
setInterval(函数名,延迟时间,参数);
setInterval:设置一个间隔时间,间隔多久会触发一次!除非 remove,否则会永久执行下去!
[plain] view plaincopy
- public class SetIntervalExample extends Sprite {
- private var intervalDuration:Number = 1000; // duration between intervals, in milliseconds
- private var counter:uint = 0;
- private var stopCount:uint = 3;
- public function SetIntervalExample()
- {
- var intervalId:uint = setInterval(myRepeatingFunction, intervalDuration, "Hello", "World");
- }
- public function myRepeatingFunction():void
- {
- trace(arguments[0] + " " + arguments[1]);
- counter++;
- if(counter == stopCount)
- {
- trace("Clearing Interval");
- clearInterval(intervalId);
- }
- }
- }
2、
setTimeOut(函数名,延迟时间,参数);
setTimeOut:设置超时时间,只会执行一次!
以下示例使用 setTimeout()
方法在指定的延迟期之后调用另一个方法。
[plain] view plaincopy
- package {
- import flash.display.Sprite;
- import flash.utils.*;
- public class SetTimeoutExample extends Sprite {
- private var delay:Number = 1000; // delay before calling myDelayedFunction
- public function SetTimeoutExample()
- {
- var intervalId:uint = setTimeout(myDelayedFunction, delay, "Hello", "World");
- }
- public function myDelayedFunction():void
- {
- trace(arguments[0] + " " + arguments[1]);
- }
- public function clearTimeout():void
- {
- if(intervalId>0)
- {
- clearTimeout(intervalId);
- }
- }
- }
- }
复制去Google翻译翻译结果
时间: 2024-10-19 23:51:33