User Guide
96 ActionScript language elements
setInterval function
setInterval(functionReference:Function, interval:Number, [param1:Object,
param2, ..., paramN]) : Number
setInterval(objectReference:Object, methodName:String, interval:Number,
[param1:Object, param2, ..., paramN]) : Number
Calls a function or a method of an object at periodic intervals while a SWF file plays. You can
use
setInterval() to execute any function repetitively over time.
Use the following tips when working with
setInterval():
■ Identify the scope of the function being called.
■ Identify the scope where the interval ID (the return value of setInterval()) was set.
■ Clear previously set intervals before starting new ones.
These tips are discussed in further detail in the following paragraphs.
Identify the scope of the function being called. To identify the scope of the function being
called, pass the object where the
setInterval() method can execute (the object scope) as the
first parameter and the method name you want to execute as the second parameter (as shown
in the second signature). This ensures that the desired method is executed from the scope of
the object reference passed in. When the method is executed in this manner, it can reference
member variables on the object using the
this keyword.
Identify the scope where the interval identifier was set. To identify the scope where the
interval identifier (
intervalId) was set, you can assign it to a member variable on the object
scope that you pass to
setInterval(). In this way, the function being called can locate the
interval identifier at
this.intervalId.
Clear previously set intervals. To clear previously set intervals before starting new ones, you
should usually call
clearInterval()before calling setInterval(). This ensures that you do
not overwrite or otherwise destroy your
intervalId variable, which is the only reference to
the currently running interval. To call
clearInterval() prior to calling setInterval(),
both the initiating script and the script being executed must have access to the
intervalId, as
shown in the Examples.
Availability: ActionScript 1.0; Flash Player 6
Parameters
functionReference:Function - A reference to the function to be called.
NOTE
Always be sure to call clearinterval() when you want the script to stop looping.