User Guide

1024 Chapter 2: ActionScript Language Reference
XML.firstChild
Availability
Flash Player 5.
Usage
my_xml.firstChild:XMLNode
Description
Read-only property; evaluates the specified XML object and references the first child in the parent
nodes child list. This property is
null if the node does not have children. This property is
undefined if the node is a text node. This is a read-only property and cannot be used to
manipulate child nodes; use the
appendChild(), insertBefore(), and removeNode() methods
to manipulate child nodes.
Example
The following example shows how to use XML.firstChild to loop through a nodes child nodes:
// create a new XML document
var doc:XML = new XML();
// create a root node
var rootNode:XMLNode = doc.createElement("rootNode");
// create three child nodes
var oldest:XMLNode = doc.createElement("oldest");
var middle:XMLNode = doc.createElement("middle");
var youngest:XMLNode = doc.createElement("youngest");
// add the rootNode as the root of the XML document tree
doc.appendChild(rootNode);
// add each of the child nodes as children of rootNode
rootNode.appendChild(oldest);
rootNode.appendChild(middle);
rootNode.appendChild(youngest);
// use firstChild to iterate through the child nodes of rootNode
for (var aNode:XMLNode = rootNode.firstChild; aNode != null; aNode =
aNode.nextSibling) {
trace(aNode);
}
// output:
// <oldest />
// <middle />
// <youngest />
The following example is from the XML_languagePicker FLA file in the Examples directory and
can be found in the
languageXML.onLoad event handler function definition:
// loop through the strings in each language node
// adding each string as a new element in the language array