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
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
sum. The function uses a
value is added to the
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
loop to examine each argument passed. If the value is a number, the
for
variable. At the end of the function, the value of
sum
getArgLength
adds the values passed to it and returns the
listSum
, which returns the number
is returned.
sum
arguments.length
101
Need help?
Do you have a question about the FLASH MX 2004-ACTIONSCRIPT LANGUAGE and is the answer not in the manual?
Questions and answers