I want to parse an XML file with AS2, but I'm not sure how to put the retrieved values into an array of objects with the number of keys matching found values. The code has if statements to filter out unwanted elements, but the number of array keys will always equal the length limit of the for loop.
How do I create an array of objects that only contains values that are not undefined?
//AS2
var xml:XML = new XML();
xml.ignoreWhite=true;
xml.onLoad = function(success)
{
if (success)
{
var myImage = xml.firstChild.childNodes;
var img_arr = new Array();
for (i=0; i<myImage.length; i++)
{
img_arr[i] = new Object();
var nodeName = xml.firstChild.childNodes[i].NodeName;
//condition to filter out values
if (nodeName == "value")
{
img_arr[i]["file"] = xml.firstChild.childNodes[i].firstChild.NodeValue;
img_arr[i]["name"] = xml.firstChild.childNodes[i].childNodes[1].NodeValue;
}
}
//trace(img_arr.length)
}
}
xml.load("test.xml");
Returns an Array like:
img_arr[file][0] = value0
img_arr[name][0] = name0
img_arr[file][1] = undefined
img_arr[name][1] = undefined
img_arr[file][2] = value2
img_arr[name][2] = name2How do you get this array?
img_arr[file][0] = value0
img_arr[name][0] = name0
img_arr[file][1] = value2
img_arr[name][1] = name2