User Guide
setInterval() 203
setInterval()
Availability
Flash Player 6.
Usage
setInterval(functionName:Function, interval:Number [, param1:Object, param2,
..., paramN]) : Number
setInterval(objectName:Object, methodName:Function, interval:Number [,
param1:Object, param2, ..., paramN]) : Number
Parameters
functionName
A function name or a reference to an anonymous function.
interval The time in milliseconds between calls to the functionName or methodName
parameter.
param1, param2, ..., paramN Optional parameters passed to the functionName or
methodName parameter.
objectName An object containing the method methodName. You must include this parameter
when using setInterval() in an
<mx:Script> block in Flex applications.
methodName A method of objectName.
Returns
An identifying integer that you can pass to clearInterval() to cancel the interval.
Description
Function; calls a function or a method or an object at periodic intervals while a SWF file plays.
You can use an interval function to update variables from a database or to update a time display.
Example
Usage 1: The following example calls an anonymous function every 1000 milliseconds
(1 second).
setInterval( function(){ trace("interval called"); }, 1000 );
Usage 2: The following example defines two event handlers and calls each of them. Both calls to
setInterval() send the string "interval called" to the log file every 1000 milliseconds.The
first call to
setInterval() calls the callback1() function, which contains a trace()
statement. The second call to
setInterval() passes the "interval called" string to the
function
callback2() as a parameter.
function callback1() {
trace("interval called");
}
function callback2(arg) {
trace(arg);
}
CHAPTER 5
ActionScript Core Language Elements