Sunday, December 2, 2012

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
Programming Actionscript 3. Powered by Blogger.