5:23 am GMT
Examples
Examples » ActionScript
#include "xmlnitro2.as"
function myLoad () {
// this function gets executed when Flash has loaded the complete XML file
// it displays node properties for the first 4 levels of nodes found
// in the code, this = the XML object that called this function
// (eg this.firstChild = the first child node of thisXML)
trace("xml declaration: " + this.xmlDecl);
trace("xml doctype: " + this.docTypeDecl);
trace("number of articles: " + this.firstChild.childNodes.length);
trace(" ");
level1Child = this.firstChild;
level2Child = level1Child.firstChild;
level3Child = level2Child.firstChild;
level4Child = level3Child.firstChild;
// note that that last statement could also have been written
// level4Child = this.firstChild.firstChild.firstChild.firstChild; or
// level4Child = this.childNodes[0].childNodes[0].childNodes[0].childNodes[0];
trace("level1: name=" + level1Child.nodeName);
trace(" value=" + level1Child.nodeValue);
trace(" type=" + level1Child.nodeType);
trace(" ");
trace("level2: name=" + level2Child.nodeName);
trace(" value=" + level2Child.nodeValue);
trace(" type=" + level2Child.nodeType);
// the attributes property is itself an object
for (attr in level2Child.attributes) {
trace(" attributes=" + attr + " value=" + level2Child.attributes[attr]);
}
trace(" ");
trace("level3: name=" + level3Child.nodeName);
trace(" value=" + level3Child.nodeValue);
trace(" type=" + level3Child.nodeType);
// the following will not produce any output because level3Child has no attributes
for (attr in level3Child.attributes) {
trace(" attributes=" + attr + " value=" + level3Child.attributes[attr]);
}
trace(" ");
trace("level4: name=" + level4Child.nodeName);
trace(" value=" + level4Child.nodeValue);
trace(" type=" + level4Child.nodeType);
trace(" ");
trace(level3Child.nextSibling.nodeName);
trace(level3Child.nextSibling.firstChild.nodeValue);
trace(" ");
n3 = level2Child.childNodes.length;
trace("number of level3 nodes = " + n3);
trace(" 1st level3 node = " + level2Child.childNodes[0].nodeName);
trace(" 2nd level3 node = " + level2Child.childNodes[1].nodeName);
trace(" 3rd level3 node = " + level2Child.childNodes[2].nodeName);
trace(" last level3 node = " + level2Child.childNodes[n3-1].nodeName);
}
thisXML = new XML();
thisXML.ignoreWhite = true;
thisXML.onLoad = myLoad;
thisXML.load("environment_page.xml");
This category contains 2
examples, and has been viewed 58413 times.
- XML Properties - An example that works with an XML file (17195 views)
- Abstract Class - An example of an abstract class in Actionscript (13818 views)
|