User Guide

Functions 99
trace(objParam.x, objParam.y);
}
var objVar:Object = {x:10, y:15};
trace(objVar.x, objVar.y); // 10 15
passByRef(objVar); // 11 16
trace(objVar.x, objVar.y); // 11 16
The objParam parameter references the same object as the global objVar variable. As you can
see from the
trace statements in the example, changes to the x and y properties of the
objParam object are reflected in objVar object.
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 arguments object to access
information about the parameters passed to your function. Some important aspects of the
arguments object include the following:
The arguments object is an array that includes all the parameters passed to the function.
The arguments.length property reports the number of parameters passed to the
function.
The arguments.callee property provides a reference to the function itself, which is
useful for recursive calls to function expressions.
NOTE
The arguments object is not available if any parameter is named arguments or if you use
the ... (rest) parameter.