You can use functions that are built into the ActionScript language. They might be top level,
as described in
"About types of methods and functions" on page
be in a built-in class, such as Math or MovieClip, which you use as a method in your
application.
You use built-in functions in ActionScript to perform certain tasks and to access information.
For example, you can get the number of milliseconds the SWF file has been playing by using
. Or you can get the version number of Flash Player that hosts the file by using
getTimer()
. Functions that belong to an object are called methods. Functions that don't
getVersion()
belong to an object are called top-level functions and are found in subcategories of the Global
Functions category of the Actions panel.
Some built-in functions require you to pass certain values. If you pass more parameters than
the function requires, the extra values are ignored. If you don't pass a required parameter, the
empty parameters are assigned the
runtime.
To call a function, that function's definition must be in a frame that the playhead has
reached.
Top-level functions are easy to use. To call a function, simply use the function name and pass
any parameters required by that function. (For information on required parameters, see the
entry for the function in the ActionScript 2.0 Language Reference). For example, add the
following ActionScript to Frame 1 of the Timeline:
trace("my message");
When you test the SWF file,
of top-level functions are
use both of these functions together. Add the following code to Frame 1 of the Timeline:
function myTimer():Void {
trace(getTimer());
}
var intervalID:Number = setInterval(myTimer, 100);
This code creates a simple timer using
top-level functions to display the number of milliseconds since the SWF file began
trace()
to play in Flash Player.
Calling a top-level function is like calling a user-defined function. For more information, see
"Targeting and calling user-defined functions" on page
function, see its entry in ActionScript 2.0 Language Reference.
206
Functions and Methods
undefined
appears in the Output panel. Two other examples
my message
and
setInterval()
getTimer()
203; or the function might
data type, which can cause errors during
. The next example shows how to
getTimer()
, and uses the
setInterval()
213. For information on each
and
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?