
setInterval() Global Function
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
756
|
ActionScript Language Reference
setInterval() Global Function
execute a function or method every n milliseconds
Flash 6
setInterval(function, interval, arg1, arg2,...argn)
setInterval(object, method, interval, arg1, arg2,...argn)
Arguments
function A reference to the function to execute.
interval The amount of time between
function or method executions, in milliseconds.
arg1,...arg
n A list of optional arguments to pass to function or method.
object An object whose
method will be executed every interval milliseconds.
method The string name of the method to execute (must be defined on
object).
Returns
An interval identifier, used to stop the timed execution of function or method (which is
called “clearing the interval”).
Description
The setInterval() function starts an interval, which executes the specified function or
method every interval milliseconds. Here we start a very simple interval that executes the
function helloWorld() once per second:
function helloWorld () {
trace("Hello world!");
}
setInterval(helloWorld, 1000); // 1000 milliseconds is 1 second
Notice that the function reference, helloWorld, is specified without the function call oper-
ator, (). The following attempt to set an interval fails because the call operator is included
erroneously:
setInterval(helloWorld(), ...