Adobe® Flex® 4 Language Reference
Hide Packages and Classes List |  Packages  |  Classes  |  Index  |  Appendixes
__Global__ 
arguments 
PackageTop Level
Classpublic class arguments
Inheritancearguments Inheritance Object

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 8, AIR 1.0

An arguments object is used to store and access a function's arguments. Within a function's body, you can access its arguments object by using the local arguments variable.

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.

View the examples

See also



Public Properties
 PropertyDefined By
  callee : Function
A reference to the currently executing function.
arguments
 Inheritedconstructor : 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
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
Public Methods
 MethodDefined By
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Property Detail

callee

property
public var callee:Function

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 8, AIR 1.0

A reference to the currently executing function.


Example  ( How to use this example )
The following code shows how to get a reference to the function that calls the function named 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: Flash Player 8, AIR 1.0

The number of arguments passed to the function. This may be more or less than the function declares.

ArgumentsExample.as

The following example shows uses for various 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
        }
    }
}