MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual page 53

Actionscript reference guide
Hide thumbs Also See for FLASH MX 2004 - ACTIONSCRIPT:
Table of Contents

Advertisement

Returning values from a function
Use the
return
function and replaces it with the value of the
the
statement in functions:
return
If you specify a return type other than void for a function, you must include a
statement in the function.
If you specify a return type of void, you should not include a
If you don't specify a return type, including a
include one, an empty string is returned.
For example, the following function returns the square of the parameter
returned value must be a Number:
function sqr(x):Number {
return x * x;
}
Some functions perform a series of tasks without returning a value. For example, the following
function initializes a series of global variables:
function initialize() {
boat_x = _global.boat._x;
boat_y = _global.boat._y;
car_x = _global.car._x;
car_y = _global.car._y;
}
Calling a user-defined function
You can use a target path to call a function in any Timeline from any Timeline, including from
the Timeline of a loaded SWF file. If a function was declared using the
not need to use a target path to call it.
To call a function, enter the target path to the name of the function, if necessary, and pass any
required parameters inside parentheses. For example, the following statement invokes the
function
in the movie clip
sqr()
and stores the result in the variable
var temp = _root.MathLib.sqr(3);
The following example uses an absolute path to call the
on the main Timeline and requires no parameters:
_root.initialize();
The following example uses a relative path to call the
functionsClip
_parent.functionsClip.list(6);
statement to return values from functions. The
MathLib
temp
movie clip:
action. The following rules govern the use of
return
statement is optional. If you don't
return
on the main Timeline, passes the parameter 3 to it,
:
initialize()
function that was defined in the
list()
statement stops the
return
return
statement.
return
and specifies that the
x
identifier, you do
_global
function that was defined
Creating functions
53

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?

Questions and answers

Table of Contents