User Guide

arguments.length 101
arguments.length
Availability
Flash Player 5.
Usage
arguments.length:Number
Description
Property; the number of parameters actually passed to a function.
Example
The following ActionScript includes a function called getArgLength, which returns the number
of arguments that are passed into the function. Although the method expects three arguments,
you can pass as many arguments as you want.
function getArgLength(param_arg1:String, param_arg2:String, param_arg3:String)
{
return (arguments.length);
}
trace(getArgLength("one", "two", "three")); // output: 3
trace(getArgLength("one", "two")); // output: 2
trace(getArgLength("one", "two", "three", "four")); // output: 4
In the following example, the function called listSum adds the values passed to it and returns the
sum. The function uses a
for loop to examine each argument passed. If the value is a number, the
value is added to the
sum variable. At the end of the function, the value of sum is returned.
function listSum():Number {
var sum:Number = 0;
for (var i = 0; i<arguments.length; i++) {
if (!isNaN(Number(arguments[i]))) {
sum += parseFloat(arguments[i]);
}
}
return sum;
}
trace(listSum(100, 200, 300, 7)); // output: 607