Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > XMLNode > lastChild (XMLNode.lastChild property) | |||
public lastChild : XMLNode [read-only]
An XMLNode value that references the last child in the node's child list. The XML.lastChild property is null if the node does not have children. This property cannot be used to manipulate child nodes; use the appendChild(), insertBefore(), and removeNode() methods to manipulate child nodes.
Availability: ActionScript 1.0; Flash Player 5
The following example uses the XML.lastChild property to iterate through the child nodes of an XML node, beginning with the last item in the node's child list and ending with the first child of the node's child list:
// 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 lastChild to iterate through the child nodes of rootNode
for (var aNode:XMLNode = rootNode.lastChild; aNode != null; aNode = aNode.previousSibling) {
trace(aNode);
}
// output:
// <youngest />
// <middle />
// <oldest />
The following example creates a new XML packet and uses the XML.lastChild property to iterate through the child nodes of the root node:
// create a new XML document
var doc:XML = new XML("");
var rootNode:XMLNode = doc.firstChild;
// use lastChild to iterate through the child nodes of rootNode
for (var aNode:XMLNode = rootNode.lastChild; aNode != null; aNode=aNode.previousSibling) {
trace(aNode);
}
// output:
// <youngest />
// <middle />
// <oldest />
appendChild (XMLNode.appendChild method), insertBefore (XMLNode.insertBefore method), removeNode (XMLNode.removeNode method), XML
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00002354.html