Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript language elements > Global Functions > setTimeout function | |||
setTimeout() : Number
Runs a specified function after a specified delay (in milliseconds). The setTimeout() function is similar to the setInterval() function, except that setTimeout() calls the function once and then is automatically deleted.
To preserve the ability to use the clearTimeout() method to prevent setTimeout() from calling the function, be sure to assign the return value of the setTimeout() call to a variable.
Availability: ActionScript 1.0; Flash Player 8
functionReference:Object - The name of the function to execute. Do not include quotation marks or parentheses, and do not specify parameters of the function to call. For example, use functionName, not functionName() or functionName(param).
delay:Number - The delay, in milliseconds, until the function is executed.
args:Object - Zero or more arguments, separated by commas, to be passed to the function.
Number - Unique numeric identifier for the timed process.
The following example uses setTimeout() to call a function named my_delayedFunction after a two(2) second delay, and uses the return value to call clearTimeout() if the user presses the Escape key. The example will output the string "two second delay" after two seconds has elapsed, unless the user presses the Escape key before my_delayedFunction is called.
var my_timedProcess:Number = setTimeout(my_delayedFunction, 2000, "two second delay");
function my_delayedFunction (arg1) {
trace(arg1);
}
var escListener:Object = new Object();
escListener.onKeyDown = function() {
if (Key.isDown(Key.ESCAPE)) {
clearTimeout(my_timedProcess);
}
};
Key.addListener(escListener);
When you use this example, be sure to select Control > Disable Keyboard Shortcuts in the test environment.
clearTimeout function, setInterval function
Flash CS3
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00001218.html
Comments
glance.ca said on Aug 28, 2007 at 11:14 AM : ufitzi said on Oct 5, 2007 at 7:36 AM : No screen name said on Feb 28, 2008 at 10:46 PM : punchkickinteractive said on Apr 18, 2008 at 5:20 AM :