MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE Reference page 1331

Actionscript 2.0 language reference
Table of Contents

Advertisement

Example
The following example creates an element node and a text node, and checks the node name of
each:
// create an XML document
var doc:XML = new XML();
// create an XML node using createElement()
var myNode:XMLNode = doc.createElement("rootNode");
// place the new node into the XML tree
doc.appendChild(myNode);
// create an XML text node using createTextNode()
var myTextNode:XMLNode = doc.createTextNode("textNode");
// place the new node into the XML tree
myNode.appendChild(myTextNode);
trace(myNode.nodeName);
trace(myTextNode.nodeName);
// output:
// rootNode
// null
The following example creates a new XML packet. If the root node has child nodes, the code
loops over each child node to display the name and value of the node. Add the following
ActionScript to your FLA or AS file:
var my_xml:XML = new XML("hankrudolph");
if (my_xml.firstChild.hasChildNodes()) {
// use firstChild to iterate through the child nodes of rootNode
for (var aNode:XMLNode = my_xml.firstChild.firstChild; aNode != null;
aNode=aNode.nextSibling) {
if (aNode.nodeType == 1) {
trace(aNode.nodeName+":\t"+aNode.firstChild.nodeValue);
}
}
}
The following node names are displayed in the Output panel:
output:
username: hank
password: rudolph
See also
nodeType (XMLNode.nodeType property)
XMLNode
1331

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flash 8

Table of Contents