Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > Function > call (Function.call method) | |||
Invokes the function represented by a Function object. Every function in ActionScript is represented by a Function object, so all functions support this method.
In almost all cases, the function call (()) operator can be used instead of this method. The function call operator produces code that is concise and readable. This method is primarily useful when the thisObject parameter of the function invocation needs to be explicitly controlled. Normally, if a function is invoked as a method of an object, within the body of the function, thisObject is set to myObject, as shown in the following example:
myObject.myMethod(1, 2, 3);
In some situations, you might want thisObject to point somewhere else; for example, if a function must be invoked as a method of an object, but is not actually stored as a method of that object:
myObject.myMethod.call(myOtherObject, 1, 2, 3);
You can pass the value null for the thisObject parameter to invoke a function as a regular function and not as a method of an object. For example, the following function invocations are equivalent:
Math.sin(Math.PI / 4) Math.sin.call(null, Math.PI / 4)
Returns the value that the called function specifies as the return value.
Availability: ActionScript 1.0; Flash Player 6
thisObject:Object - An object that specifies the value of thisObject within the function body.
parameter1:Object [optional] - A parameter to be passed to the myFunction. You can specify zero or more parameters.
Object -
The following example uses Function.call() to make a function behave as a method of another object, without storing the function in the object:
function myObject() {
}
function myMethod(obj) {
trace("this == obj? " + (this == obj));
}
var obj:Object = new myObject();
myMethod.call(obj, obj);
The trace() statement displays:
this == obj? true
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00001690.html