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.

Le co<strong>de</strong> suivant peut ensuite être placé dans un fichier FLA et fonctionner <strong>de</strong> la même façon<br />

que dans les exemples précé<strong>de</strong>nts :<br />

var myBook:Book = new Book();<br />

myBook.bookcount = 5;<br />

trace("You or<strong>de</strong>red "+myBook.bookcount+" copies of "+myBook.bookname);<br />

Voir également<br />

Instruction get, Instruction set<br />

constructeur (propriété Object.constructor)<br />

public constructor : Object<br />

Référence à la fonction constructeur pour une occurrence d'objet donnée. La propriété<br />

constructor est automatiquement affectée à tous les objets au moment <strong>de</strong> leur création à<br />

l'ai<strong>de</strong> <strong>du</strong> constructeur <strong>de</strong> la classe Object.<br />

Disponibilité : <strong>ActionScript</strong> 1.0 ; Flash Player 5<br />

Exemple<br />

L'exemple suivant constitue une référence à la fonction constructor pour l'objet myObject.<br />

var my_str:String = new String("sven");<br />

trace(my_str.constructor == String); //output: true<br />

Si vous utilisez l'opérateur instanceof, vous pouvez également déterminer si un objet<br />

appartient à une classe spécifiée :<br />

var my_str:String = new String("sven");<br />

trace(my_str instanceof String); //output: true<br />

Cependant, dans l'exemple suivant, la propriété Object.constructor convertit les types <strong>de</strong><br />

données primitifs (tels que le littéral <strong>de</strong> chaîne affiché ici) en objets enveloppe. L'opérateur<br />

instanceof n'effectue aucune conversion, comme il est indiqué dans l'exemple suivant :<br />

var my_str:String = "sven";<br />

trace(my_str.constructor == String); //output: true<br />

trace(my_str instanceof String); //output: false<br />

Voir également<br />

Opérateur instanceof<br />

1030 Chapitre 2: Classes <strong>ActionScript</strong>

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

Saved successfully!

Ooh no, something went wrong!