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 />

L'exemple ci-<strong>de</strong>ssous montre comment lire et écrire les attributs <strong>du</strong> nœud XML :<br />

var doc:XML = new XML(" item ");<br />

trace(doc.firstChild.attributes.name); // Val<br />

doc.firstChild.attributes.or<strong>de</strong>r = "first";<br />

trace (doc.firstChild); // item <br />

for (attr in doc.firstChild.attributes) {<br />

trace (attr + " = " + doc.firstChild.attributes[attr]);<br />

}<br />

// or<strong>de</strong>r = first<br />

// name = Val<br />

childNo<strong>de</strong>s (XMLNo<strong>de</strong>.childNo<strong>de</strong>s, propriété)<br />

public childNo<strong>de</strong>s : Tableau [lecture seule]<br />

Tableau <strong>de</strong>s enfants <strong>de</strong> l'objet XML spécifié. Chaque élément <strong>du</strong> tableau est une référence vers<br />

un objet XML qui représente un nœud enfant. Cette propriété est en lecture seule et ne peut<br />

pas être utilisée pour manipuler les nœuds enfants. Utilisez les métho<strong>de</strong>s appendChild(),<br />

insertBefore(), et removeNo<strong>de</strong>() pour manipuler les nœuds enfants.<br />

Cette propriété n'est pas définie pour les nœuds <strong>de</strong> texte (no<strong>de</strong>Type == 3).<br />

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

Exemple<br />

L'exemple suivant indique comment utiliser la propriété XML.childNo<strong>de</strong>s pour renvoyer un<br />

tableau récapitulatif <strong>de</strong>s nœuds enfants :<br />

// create a new XML document<br />

var doc:XML = new XML();<br />

// create a root no<strong>de</strong><br />

var rootNo<strong>de</strong>:XMLNo<strong>de</strong> = doc.createElement("rootNo<strong>de</strong>");<br />

// create three child no<strong>de</strong>s<br />

var ol<strong>de</strong>st:XMLNo<strong>de</strong> = doc.createElement("ol<strong>de</strong>st");<br />

var middle:XMLNo<strong>de</strong> = doc.createElement("middle");<br />

var youngest:XMLNo<strong>de</strong> = doc.createElement("youngest");<br />

// add the rootNo<strong>de</strong> as the root of the XML document tree<br />

doc.appendChild(rootNo<strong>de</strong>);<br />

// add each of the child no<strong>de</strong>s as children of rootNo<strong>de</strong><br />

rootNo<strong>de</strong>.appendChild(ol<strong>de</strong>st);<br />

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

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

Saved successfully!

Ooh no, something went wrong!