Package | Top Level |
Class | public class arguments |
Inheritance | arguments ![]() |
Language Version: | ActionScript 3.0 |
Runtime Versions: | 1.0, 8 |
The arguments are stored as array elements: the first is accessed as
arguments[0]
, the second as
arguments[1]
, and so on. The
arguments.length
property indicates the number of arguments passed to
the function. There may be a different number of arguments passed than
the function declares.
Unlike previous versions of ActionScript, ActionScript 3.0 has no
arguments.caller
property.
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 includes a new
...(rest)
keyword that is recommended instead of the
arguments class.
See also
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 |
callee | property |
public var callee:Function
Language Version: | ActionScript 3.0 |
Runtime Versions: | 1.0, 8 |
A reference to the currently executing function.
secondFunction()
. The
firstFunction()
function has
the Boolean argument of
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. 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
firstFunction()
, 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); } } }
length | property |
public var length:Number
Language Version: | ActionScript 3.0 |
Runtime Versions: | 1.0, 8 |
The number of arguments passed to the function. This may be more or less than the function declares.
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 } } }