| |
Action Script - Loading XML Information
Moving one to more complex programming, this is a frame script for loading the information form an XML document. To be placed on the frame in which the information is to be loaded. First you establish two arrays (to keep it simple we are assuming your XML document has only two categories.) Next the xml object is established. "ignorewhite" is import to ignore all spaces in the xml. You are going to make the "rootElement" variable equal to the root category of your XML. The variable "xmlElements" become the number of elements under the root. Then you fill the two arrays with the first two categories under the root. You need to supply the path to your xml document in the last line.
_global.firstNodeArray = new Array();
_global.secondNodeArray = new Array();
myXml_xml = new XML();
myXml_xml.ignoreWhite = true;
myXml_xml.onLoad = function(success) {
if (success) {
var rootElement_xml:XMLNode = myXml_xml.firstChild;
var xmlElements:Number = rootElement_xml.firstChild.childNodes.length;
for (i=0; i<xmlElements; i++) {
_global.firstNodeArray[i] = (rootElement_xml.firstChild.childNodes[i].childNodes[0].firstChild);
_global.secondNodeArray[i] = (rootElement_xml.firstChild.childNodes[i].childNodes[1].firstChild);
}
}
}
myXml_xml.load('YOUR XML PATH HERE');
|