03.05.2013 Views

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

// instantiate an object<br />

var myObj:Object = new Object();<br />

// create arrays to pass as a parameter to apply()<br />

var firstArray:Array = new Array(1,2,3);<br />

var secondArray:Array = new Array("a", "b", "c");<br />

// use apply() to set the value of this to be myObj <strong>and</strong> send firstArray<br />

theFunction.apply(myObj,firstArray);<br />

// output:<br />

// this == myObj? true<br />

// arguments: 1,2,3<br />

// use apply() to set the value of this to be myObj <strong>and</strong> send secondArray<br />

theFunction.apply(myObj,secondArray);<br />

// output:<br />

// this == myObj? true<br />

// arguments: a,b,c<br />

See also<br />

call (Function.call method)<br />

call (Function.call method)<br />

public call(thisObject:Object, [parameter1:Object]) : Object<br />

Invokes the function represented by a Function object. Every function in <strong>ActionScript</strong> is<br />

represented by a Function object, so all functions support this method.<br />

In almost all cases, the function call (()) operator can be used instead of this method. The<br />

function call operator produces code that is concise <strong>and</strong> readable. This method is primarily<br />

useful when the thisObject parameter of the function invocation needs to be explicitly<br />

controlled. Normally, if a function is invoked as a method of an object, within the body of the<br />

function, thisObject is set to myObject, as shown in the following example:<br />

myObject.myMethod(1, 2, 3);<br />

In some situations, you might want thisObject to point somewhere else; for example, if a<br />

function must be invoked as a method of an object, but is not actually stored as a method of<br />

that object:<br />

myObject.myMethod.call(myOtherObject, 1, 2, 3);<br />

You can pass the value null for the thisObject parameter to invoke a function as a regular<br />

function <strong>and</strong> not as a method of an object. For example, the following function invocations<br />

are equivalent:<br />

606 <strong>ActionScript</strong> classes

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!