Hey guys, im using a function that iterates through all nodes in an XML tree, and then calls itself again if any of the nodes it is looking at has a set of child nodes, so in other words it multi-dimensionally loops through the entire XML tree.
heres my code
function loopThroughNode(childNodeSet:Object, containingArray:Array):Void {
//
for (var i:Number = 0; i<childNodeSet.length; i++) {
var tempObject:Object = new Object();
//
setupData(tempObject, childNodeSet*.childNodes);
//
if (childNodeSet*.childNodes.length>2) {
for (var k:Number = 2; k<childNodeSet*.childNodes.length; k++) {
//
var NewNodeName:String = childNodeSet*.childNodes[k].nodeName;
tempObject[NewNodeName] = new Array();
//
loopThroughNode(childNodeSet*.childNodes[k].childNodes, tempObject[NewNodeName]);
//
}
}
}
//
containingArray.push(tempObject);
//
return;
}
one question i have is - am i correct in my assumption that while variables declared within a function are not accessible anywhere but within that function, if a function calls itself, any loops within that function that use a variable such as “i” will be affected seeing as “i” is accessible within the function?
if so, how do i get around that? currently my function loops through all the way down to last child node it can find along the first branch of the XML tree, but then doesnt continue looping through the other branches…
anyone who understands what im trying to do and has any suggestions would be much appreciated :pleased: