ActionScript 3.0 Language and Components Reference | All Packages | All Classes | Language Elements | Index | Appendixes | Conventions | Frames No Frames |
arguments

Package | Top Level
Class | public class arguments
Inheritance | arguments Object

Language Version : | ActionScript 3.0

Player Version : | Flash Player 8

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

...(rest)
Function

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| 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 Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toString():String Returns the string representation of the specified object. | Object
|  | valueOf():Object Returns the primitive value of the specified object. | Object

Property Detail

callee | property

`public var callee:Function`

Language Version : | ActionScript 3.0

Player Version : | Flash Player 8

A reference to the currently executing function.

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

Player Version : | Flash Player 8

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

Examples How to use examples
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
            }
        }
    }

Submit Feedback on LiveDocs
© 2004-2008 Adobe Systems Incorporated. All rights reserved.
Tue May 20 2008, 04:02 AM -07:00