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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Exemple<br />

Utilisation 1 : L'exemple suivant crée un objet, l'utilise, puis le supprime lorsqu'il n'est plus<br />

requis :<br />

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

account.name = "Jon";<br />

account.balance = 10000;<br />

trace(account.name); //output: Jon<br />

<strong>de</strong>lete account;<br />

trace(account.name); //output: un<strong>de</strong>fined<br />

Utilisation 2 : L'exemple suivant supprime une propriété d'un objet :<br />

// create the new object "account"<br />

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

// assign property name to the account<br />

account.name = "Jon";<br />

// <strong>de</strong>lete the property<br />

<strong>de</strong>lete account.name;<br />

Utilisation 3 : L'exemple suivant supprime une propriété d'objet :<br />

var my_array:Array = new Array();<br />

my_array[0] = "abc"; // my_array.length == 1<br />

my_array[1] = "<strong>de</strong>f"; // my_array.length == 2<br />

my_array[2] = "ghi"; // my_array.length == 3<br />

// my_array[2] is <strong>de</strong>leted, but Array.length is not changed<br />

<strong>de</strong>lete my_array[2];<br />

trace(my_array.length); // output: 3<br />

trace(my_array); // output: abc,<strong>de</strong>f,un<strong>de</strong>fined<br />

Utilisation 4 : L'exemple suivant illustre le comportement <strong>de</strong> l'instruction <strong>de</strong>lete sur <strong>de</strong>s<br />

références à un objet :<br />

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

ref1.name = "Jody";<br />

// copy the <strong>reference</strong> variable into a new variable<br />

// and <strong>de</strong>lete ref1<br />

ref2 = ref1;<br />

<strong>de</strong>lete ref1;<br />

trace("ref1.name "+ref1.name); //output: ref1.name un<strong>de</strong>fined<br />

trace("ref2.name "+ref2.name); //output: ref2.name Jody<br />

Si ref1 n'avait pas été copié dans ref2, l'objet aurait été supprimé au moment <strong>de</strong> la<br />

suppression <strong>de</strong> ref1 car il ne contient aucune référence. Si vous supprimez ref2, il n'existe<br />

aucune référence à l'objet ; celui-ci sera détruit et la mémoire qu'il utilisait <strong>de</strong>vient disponible.<br />

Voir également<br />

Instruction var<br />

Instructions 207

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

Saved successfully!

Ooh no, something went wrong!