![MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual Download Page 805](http://html1.mh-extra.com/html/macromedia/flash-mx-2004-actionscript/flash-mx-2004-actionscript_reference-manual_3378897805.webp)
About ActionScript 1
805
Invoking a function using the Function.call() method in ActionScript 1
The
Function.call()
method invokes the function represented by a Function object.
In almost all cases, the function call operator (
()
) can be used instead of the
call()
method. The
function call operator creates code that is concise and readable. The
call()
method is primarily
useful when the
this
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,
this
is set to
myObject
, as in the following:
myObject.myMethod(1, 2, 3);
In some situations, you may want
this
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)
For more information, see
Function.call()
in
Chapter 12, “ActionScript Dictionary,”
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
thisObject
specifies the value of
this
within the function body.
■
The parameters
parameter1
...,
parameterN
specify parameters to be passed to
myFunction
. You can specify zero or more parameters.
Specifying the object to which a function is applied using Function.apply()
in ActionScript 1
The
Function.apply()
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.
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
Function.apply()
in
Chapter 12, “ActionScript Dictionary,”
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
thisObject
specifies the object that
myFunction
is applied to.
■
The parameter
argumentsObject
defines an array whose elements are passed to
myFunction
as parameters.
Summary of Contents for FLASH MX 2004 - ACTIONSCRIPT
Page 1: ...ActionScript Reference Guide...
Page 8: ...8 Contents...
Page 12: ......
Page 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Page 54: ...54 Chapter 2 ActionScript Basics...
Page 80: ...80 Chapter 3 Writing and Debugging Scripts...
Page 82: ......
Page 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Page 112: ......
Page 120: ...120 Chapter 6 Using the Built In Classes...
Page 176: ......
Page 192: ...192 Chapter 10 Working with External Data...
Page 202: ...202 Chapter 11 Working with External Media...
Page 204: ......
Page 782: ...782 Chapter 12 ActionScript Dictionary...
Page 793: ...Other keys 793 221 222 Key Key code...
Page 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Page 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Page 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Page 816: ...816 Index...