03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

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.

var myTextNode:XMLNode = doc.createTextNode("textNode");<br />

// place the new node into the XML tree<br />

myNode.appendChild(myTextNode);<br />

trace(myNode.nodeName);<br />

trace(myTextNode.nodeName);<br />

// output:<br />

// rootNode<br />

// null<br />

The following example creates a new XML packet. If the root node has child nodes, the code<br />

loops over each child node to display the name <strong>and</strong> value of the node. Add the following<br />

ActionScript to your FLA or AS file:<br />

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

if (my_xml.firstChild.hasChildNodes()) {<br />

// use firstChild to iterate through the child nodes of rootNode<br />

for (var aNode:XMLNode = my_xml.firstChild.firstChild; aNode != null;<br />

aNode=aNode.nextSibling) {<br />

if (aNode.nodeType == 1) {<br />

trace(aNode.nodeName+":\t"+aNode.firstChild.nodeValue);<br />

}<br />

}<br />

}<br />

The following node names are displayed in the Output panel:<br />

output:<br />

username: hank<br />

password: rudolph<br />

See also<br />

nodeType (XMLNode.nodeType property)<br />

nodeType (XMLNode.nodeType property)<br />

public nodeType : Number [read-only]<br />

A nodeType value, either 1 for an XML element or 3 for a text node.<br />

The nodeType is a numeric value from the NodeType enumeration in the W3C DOM Level<br />

1 recommendation: www.w3.org/tr/1998/REC-DOM-Level-1-19981001/level-onecore.html.<br />

The following table lists the values:<br />

Integer value Defined constant<br />

1 ELEMENT_NODE<br />

2 ATtrIBUTE_NODE<br />

708 ActionScript classes

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

Saved successfully!

Ooh no, something went wrong!