Hi, I created a prototype function for the Array object. It’s supposed to load and parse an XML file, then take all the values from the XML file and convert them to objects, which I then want to push to the array that called the function. However, I can’t seem to get it to work. The function itself seems to work, but the push to the array does not. Can anyone take a look at this code and give me hand? (code below)
Thanks!
Sarah
Array.prototype.xmltoArrObj = function( path ) {
var xmlurl:String = "nav/" + path + ".xml";
var attr:String = "";
var val:String = "";
var my_xml = new XML;
my_xml.ignoreWhite = true;
my_xml.onLoad = function() {
if ( success == false ) {
return;
}
// create an array of all the childNodes of the firstChild
thisTree = this.firstChild.childNodes;
for ( var n=0; n<thisTree.length; n++ ) {
// extract attributes
attr = thisTree[n].attributes.id;
// extract nodeValues
val = thisTree[n].childNodes[0].nodeValue;
// trace( "Attr: " + attr );
// trace( "Val: " + val );
// create an object to store the key/value pairs
odata = { id: attr, val: val };
trace ( "Object " + n + " is " + odata.val );
// add the object to the array
this.push(odata);
}
}
my_xml.load( xmlurl );
};