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 suivant illustre comment utiliser la métho<strong>de</strong> XML.cloneNo<strong>de</strong>() pour créer la copie<br />

d'un nœud :<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 />

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

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

// create a copy of the middle no<strong>de</strong> using cloneNo<strong>de</strong>()<br />

var middle2:XMLNo<strong>de</strong> = middle.cloneNo<strong>de</strong>(false);<br />

// insert the clone no<strong>de</strong> into rootNo<strong>de</strong> between the middle and youngest no<strong>de</strong>s<br />

rootNo<strong>de</strong>.insertBefore(middle2, youngest);<br />

trace(rootNo<strong>de</strong>);<br />

// output (with line breaks ad<strong>de</strong>d):<br />

// <br />

// <br />

// <br />

// <br />

// <br />

// <br />

// create a copy of rootNo<strong>de</strong> using cloneNo<strong>de</strong>() to <strong>de</strong>monstrate a <strong>de</strong>ep copy<br />

var rootClone:XMLNo<strong>de</strong> = rootNo<strong>de</strong>.cloneNo<strong>de</strong>(true);<br />

// insert the clone, which contains all child no<strong>de</strong>s, to rootNo<strong>de</strong><br />

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

trace(rootNo<strong>de</strong>);<br />

// output (with line breaks ad<strong>de</strong>d):<br />

// <br />

// <br />

// <br />

// <br />

// <br />

// <br />

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

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

Saved successfully!

Ooh no, something went wrong!