Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 99

Programming actionscript 3.0
Table of Contents

Advertisement

trace(objParam.x, objParam.y);
}
var objVar:Object = {x:10, y:15};
trace(objVar.x, objVar.y); // 10 15
passByRef(objVar);
trace(objVar.x, objVar.y); // 11 16
The
parameter references the same object as the global
objParam
see from the
statements in the example, changes to the
trace
object are reflected in
objParam
Default parameter values
New in ActionScript 3.0 is the ability to declare default parameter values for a function. If a
call to a function with default parameter values omits a parameter with default values, the
value specified in the function definition for that parameter is used. All parameters with
default values must be placed at the end of the parameter list. The values assigned as default
values must be compile-time constants. The existence of a default value for a parameter
effectively makes that parameter an optional parameter. A parameter without a default value is
considered a required parameter.
For example, the following code creates a function with three parameters, two of which have
default values. When the function is called with only one parameter, the default values for the
parameters are used.
function defaultValues(x:int, y:int = 3, z:int = 5):void
{
trace(x, y, z);
}
defaultValues(1); // 1 3 5
The arguments object
When parameters are passed to a function, you can use the
information about the parameters passed to your function. Some important aspects of the
object include the following:
arguments
The
object is an array that includes all the parameters passed to the function.
arguments
The
arguments.length
function.
The
arguments.callee
useful for recursive calls to function expressions.
The arguments object is not available if any parameter is named arguments or if you use
the ... (rest) parameter.
// 11 16
object.
objVar
property reports the number of parameters passed to the
property provides a reference to the function itself, which is
variable. As you can
objVar
and
properties of the
x
y
object to access
arguments
Functions
99

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents