03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - 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.

The parameters are specified as an Array object, unlike Function.call(), which specifies<br />

parameters as a comma-delimited list. This is often useful when the number of parameters to<br />

be passed is not known until the script actually executes.<br />

Returns the value that the called function specifies as the return value.<br />

Parameters<br />

thisObject:Object - The object to which myFunction is applied.<br />

argArray:Array [optional] - An array whose elements are passed to myFunction as<br />

parameters.<br />

Returns<br />

Any value that the called function specifies.<br />

Example<br />

The following function invocations are equivalent:<br />

Math.atan2(1, 0)<br />

Math.atan2.apply(null, [1, 0])<br />

The following simple example shows how apply() passes an array of parameters:<br />

function theFunction() {<br />

trace(arguments);<br />

}<br />

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

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

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

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

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

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

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

// outputs a,b,c<br />

The following example shows how apply() passes an array of parameters <strong>and</strong> specifies the<br />

value of this:<br />

// define a function<br />

function theFunction() {<br />

trace("this == myObj? " + (this == myObj));<br />

trace("arguments: " + arguments);<br />

}<br />

// instantiate an object<br />

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

342 ActionScript classes

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

Saved successfully!

Ooh no, something went wrong!