The parameter
initials
exists while the function is called and ceases to exist when the function exits. If you omit
parameters during a function call, the omitted parameters are passed as
extra parameters in a function call that are not required by the function declaration, they
are ignored.
Using variables in a function
Local variables are valuable tools for organizing code and making it easy to understand. When a
function uses local variables, it can hide its variables from all other scripts in the SWF file; local
variables are scoped to the body of the function and cease to exist when the function exits. Any
parameters passed to a function are also treated as local variables.
You can also use global and regular variables in a function. However, if you modify global or
regular variables, it is good practice to use script comments to document these modifications.
Returning values from a function
Use the
return
function and replaces it with the value of the
to use the
return
•
If you specify a return type other than Void for a function, you must include a
statement followed by the returned value in the function.
•
If you specify a return type of Void, you generally do not need to include a
•
No matter what the return type, you can use a return statement to exit from the middle of a
function, provided the return statement is followed by a return value, according to the previous
rules.
•
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):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;
}
in the function
statement to return values from functions. The
statement in functions:
fillOutScorecard()
statement. The following rules govern how
return
statement is optional. If you don't
return
is similar to a local variable; it
. If you provide
undefined
statement stops the
return
return
return
and specifies that the
x
Creating functions
statement.
43
Need help?
Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?