| Package | Top Level |
| Class | public class arguments |
| Inheritance | arguments Object |
arguments object is used to store and access a function's arguments.
While inside the function's body it can be accessed with the local arguments
variable.
The arguments are stored as array elements, the first is accessed as
arguments[0], the second as arguments[1], etc. The
arguments.length property indicates the number of arguments passed to
the function. Note that there may be a different number of arguments passed in than
the function declares.
ActionScript 3.0 has no arguments.caller property, which did exist in previous versions of
ActionScript. To get a reference to the function
that called the current function, you must pass a reference to that function as an
argument. An example of this technique can be found in the example for arguments.callee.
ActionScript 3.0 supports a new ...(rest) statement that is recommended instead of the
arguments class.
| ...(rest) statement, Function |
| Property | Defined by | ||
|---|---|---|---|
| callee : Function
A reference to the currently executing function.
| arguments | ||
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance.
| Object | |
| length : Number
The number of arguments passed to the function.
| arguments | ||
![]() | prototype : Object
[static]
A reference to the prototype object of a class or function object.
| Object | |
public var callee:Function
secondFunction(). The firstFunction() function has
the Boolean argument of value true
to demonstrate that secondFunction() successfully calls firstFunction() and
to prevent an infinite loop of each function calling the other.
Because the callSecond parameter is true, firstFunction()
calls secondFunction() and passes a reference to itself as the only
argument. The function secondFunction() receives this argument and stores it
using a parameter named caller, which is of data type Function
(note the capital "F"). From within secondFunction(), the
caller parameter is then used to call the firstFunction function,
but this time with the callSecond argument set to false.
When execution returns to the firstFunction() function, the trace()
statement is executed because callSecond is false.
package {
import flash.display.Sprite;
public class ArgumentsExample extends Sprite {
private var count:int = 1;
public function ArgumentsExample() {
firstFunction(true);
}
public function firstFunction(callSecond:Boolean) {
trace(count + ": firstFunction");
if(callSecond) {
secondFunction(arguments.callee);
}
else {
trace("CALLS STOPPED");
}
}
public function secondFunction(caller:Function) {
trace(count + ": secondFunction\n");
count++;
caller(false);
}
}
}
public var length:Number
arguments properties,
such as callee and length.
package {
import flash.display.Sprite;
public class ArgumentsExample extends Sprite {
public function ArgumentsExample() {
println("Hello World");
}
public function println(str:String):void {
trace(arguments.callee == this.println); // true
trace(arguments.length); // 1
trace(arguments[0]); // Hello World
trace(str); // Hello World
}
}
}