Invoking a function using the Function.call() method in ActionScript 1
The
Function.call()
In almost all cases, the function call operator (
function call operator creates code that is concise and readable. The
useful when the
this
Normally, if a function is invoked as a method of an object, within the body of the function,
is set to
, as in the following:
myObject
myObject.myMethod(1, 2, 3);
In some situations, you may want
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
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)
For more information, see
on page
205.
To invoke a function using the Function.call method:
•
Use the following syntax.
myFunction.call(thisObject, parameter1, ..., parameterN)
The method takes the following parameters:
The parameter
The parameters
. You can specify zero or more parameters.
myFunction
Specifying the object to which a function is applied using Function.apply()
in ActionScript 1
The
Function.apply()
ActionScript calls. This method also specifies the parameters to be passed to any called function.
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.
For more information, see
on page
205.
To specify the object to which a function is applied using Function.apply():
•
Use the following syntax.
myFunction.apply(thisObject, argumentsObject)
The method takes the following parameters:
The parameter
The parameter
as parameters.
myFunction
method invokes the function represented by a Function object.
parameter of the function invocation needs to be explicitly controlled.
to point somewhere else, for example, if a function must
this
for the
null
thisObject
Function.call()
specifies the value of
thisObject
parameter1..., parameterN
method specifies the value of
Function.apply()
specifies the object that
thisObject
defines an array whose elements are passed to
argumentsObject
) can be used instead of the
()
parameter to invoke a function as a regular
in
Chapter 12, "ActionScript Dictionary,"
within the function body.
this
specify parameters to be passed to
to be used within any function that
this
in
Chapter 12, "ActionScript Dictionary,"
myFunction
method. The
call()
method is primarily
call()
is applied to.
About ActionScript 1
this
805
Need help?
Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?
Questions and answers