MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 213

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

Targeting and calling user-defined functions
User-defined functions are simply functions that you create yourself to use in applications, as
opposed to functions in built-in classes that perform predefined functions. You name the
functions yourself and add statements in the function block. Previous sections cover writing
functions such as named, unnamed, and callback functions. For information on naming
functions, see
"Naming functions" on page
"Using functions in Flash" on page
You can use a target path to call a function in any timeline from any timeline, including from
a timeline of a loaded SWF file. To call a function, type the target path to the name of the
function, if necessary, and pass any required parameters inside parentheses. There are several
forms of syntax for user-defined functions. The following code uses a path to call the
function, which was defined on the current timeline and requires
initialize()
no parameters:
this.initialize();
The following example uses a relative path to call the
the
movie clip:
functionsClip
this._parent.functionsClip.list(6);
For information on writing named functions, see
For more information on parameters, see
You can also define your own named functions. For example, the following named function
is user defined:
helloWorld()
function helloWorld() {
trace("Hello world!");
};
The following example shows you how to use a user-defined function in a FLA file.
To create and call a simple user-defined function:
1.
Create a new Flash document and save it as udf.fla.
2.
Add the following ActionScript to Frame 1 of the main Timeline:
function traceHello(name:String):Void {
trace("hello, " + name + "!");
}
traceHello("world"); // hello, world!
The previous code creates a user-defined function named
argument,
, and traces a greeting message. To call the user-defined function, you can
name
call
traceHello
string value.
214.
from the same timeline as the function definition and pass a single
214, and for information on using functions, see
function, which was defined in
list()
"Writing named functions" on page
"Passing parameters to a function" on page
traceHello()
About functions and methods
207.
218.
that takes one
213

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

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?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents