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.

trace(myTextNo<strong>de</strong>.no<strong>de</strong>Name);<br />

// output:<br />

// rootNo<strong>de</strong><br />

// null<br />

L'exemple suivant crée un paquet XML : Si le nœud racine comporte <strong>de</strong>s enfants, le co<strong>de</strong><br />

s'exécute en boucle au niveau <strong>de</strong> chaque enfant pour afficher le nom et la valeur <strong>de</strong> ce nœud.<br />

Ajoutez le co<strong>de</strong> <strong>ActionScript</strong> suivant à votre fichier FLA ou AS :<br />

var my_xml:XML = new XML("hankrudolph");<br />

if (my_xml.firstChild.hasChildNo<strong>de</strong>s()) {<br />

// use firstChild to iterate through the child no<strong>de</strong>s of rootNo<strong>de</strong><br />

for (var aNo<strong>de</strong>:XMLNo<strong>de</strong> = my_xml.firstChild.firstChild; aNo<strong>de</strong> != null;<br />

aNo<strong>de</strong>=aNo<strong>de</strong>.nextSibling) {<br />

if (aNo<strong>de</strong>.no<strong>de</strong>Type == 1) {<br />

trace(aNo<strong>de</strong>.no<strong>de</strong>Name+":\t"+aNo<strong>de</strong>.firstChild.no<strong>de</strong>Value);<br />

}<br />

}<br />

}<br />

Les informations <strong>de</strong> nœud suivantes apparaissent dans le panneau Sortie :<br />

output:<br />

username: hank<br />

password: rudolph<br />

Voir également<br />

no<strong>de</strong>Type (XMLNo<strong>de</strong>.no<strong>de</strong>Type, propriété)<br />

no<strong>de</strong>Type (XMLNo<strong>de</strong>.no<strong>de</strong>Type, propriété)<br />

public no<strong>de</strong>Type : Number [lecture seule]<br />

Valeur no<strong>de</strong>Type, 1 pour un élément XML ou 3 pour un nœud texte.<br />

La valeur no<strong>de</strong>Type est une valeur numérique provenant <strong>de</strong> l'énumération No<strong>de</strong>Type <strong>de</strong> la<br />

recommandation W3C DOM Level 1 : www.w3.org/tr/1998/REC-DOM-Level-1-<br />

19981001/level-one-core.html. Le tableau suivant énumère les valeurs :<br />

Valeur <strong>de</strong> l'entier Constante définie<br />

1 ELEMENT_NODE<br />

2 ATTRIBUTE_NODE<br />

3 TEXT_NODE<br />

4 CDATA_SECTION_N<br />

ODE<br />

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

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

Saved successfully!

Ooh no, something went wrong!