I ended up finding a detailed thread on this subject which concluded that a foolproof method to see if something is an array is (at least in AS2) not entirely possible.
Luckily, the arrays I'm dealing with are created from an XML response from a server, parsed by GreenSock's XMLParser class, which transforms an XML document into a multidimensional associative array. With the GreenSock parser, if an object in the array does not have a "value" property, it is safe to assume that it contains more nodes (parsed into arrays).
So this is my final working function (also the first recursive function I've ever written, yay!):
Code:
function checkArray (pArray:Array, pWhich:String, pAttribute:String, pValue:String) {
trace("checkArray()");
var oReturn = "";
for (var i in pArray) {
var oBreak = false;
for (var j=0; j<pArray[i].length; j++) {
if (typeof(pArray[i][j].value) == "undefined") {
// This node contains more nodes.
oReturn = checkArray(pArray[i][j], pWhich, pAttribute, pValue);
if (typeof(pAttribute != "undefined")) {
// If we're filtering by attribute, see if we have a match.
if(oReturn != ""){
oBreak = true;
break;
}
}
} else if (i == pWhich) {
// We want the value of this node.
if (typeof(pAttribute) == "undefined"){
// Attributes don't matter.
oReturn = pArray[i][j].value;
oBreak = true;
break;
} else if (typeof(pArray[i][j][pAttribute]) != "undefined") {
// We want a specific attribute.
if (pArray[i][j][pAttribute] == pValue) {
oReturn = pArray[i][j].value;
oBreak = true;
break;
}
}
}
} // for (length)
if (oBreak == true) {
trace("Found " + oReturn);
break;
}
} // for (in)
return oReturn;
}
Bookmarks