03.07.2013 Views

Guide de reference du langage ActionScript 2.0 - PowWeb

Guide de reference du langage ActionScript 2.0 - PowWeb

Guide de reference du langage ActionScript 2.0 - PowWeb

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Exemple<br />

Les invocations <strong>de</strong> fonction suivantes sont équivalentes :<br />

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

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

L'exemple simple suivant illustre la façon dont la métho<strong>de</strong> apply() transmet un tableau <strong>de</strong><br />

paramètres :<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 />

L'exemple suivant illustre la façon dont la métho<strong>de</strong> apply() transmet un tableau <strong>de</strong><br />

paramètres et spécifie la valeur this :<br />

// <strong>de</strong>fine 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 />

// 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 and 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 and send secondArray<br />

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

// output:<br />

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

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

Function 619

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

Saved successfully!

Ooh no, something went wrong!