# Function.apply()

#### Availability

Flash Player 6.

#### Usage

    myFunction.apply(thisObject, argumentsObject)

#### Parameters

`thisObject` The object that `myFunction` is applied to.

`argumentsObject` An array whose elements are passed to `myFunction` as parameters.

#### Returns

Any value that the called function specifies.

#### Description

Method; specifies the value of `this` to be used within any function that ActionScript calls. This method also specifies the parameters to be passed to any called function. Because `apply` is a method of the Function object, it is also a method of every function object in ActionScript.

The parameters are specified as an Array object. This is often useful when the number of parameters to be passed is not known until the script actually executes.

#### Example

The following function invocations are equivalent:

    Math.atan2(1, 0)
    Math.atan2.apply(null, [1, 0])

You could construct a Flash movie that contains input entry fields that permit the user to enter the name of a function to invoke, and zero or more parameters to pass to the function. Pressing a "Call" button would then use the `apply` method to call the function, specifying the parameters.

In this example, the user specifies a function name in an input text field called `functionName`. The number of parameters is specified in an input text field called `numParameters`. Up to 10 parameters are specified in text fields called `parameter1`, `parameter2`, up to `parameter10`.

    on (release) {
      callTheFunction();
    }
    ...
    function callTheFunction()
    {
       var theFunction = eval(functionName.text);
       var n = Number(numParameters);
       var parameters = [];
       for (var i = 0; i < n; i++) {
          parameters.push(eval("parameter" + i));
       }
       theFunction.apply(null, parameters);
    }