I am having trouble passing an array through a function, and then accessing the array from outside the function, here is my code:
speechArray = new Array();
function loadXML(loaded) {
var arrayVar:Number = 0;
if (loaded) {
mainArray = new Array();
for (i=0; i<this.firstChild.childNodes[2].childNodes.length; i++) {
mainArray* = new Array();
for (j=0; j<this.firstChild.childNodes[2].childNodes*.childNodes[0].childNodes.length; j++) {
mainArray*[j] = new Array();
for (k=0; k<this.firstChild.childNodes[2].childNodes*.childNodes[0].childNodes[j].childNodes.length; k++) {
mainArray*[j][k] = new Speech(this.firstChild.childNodes[2].childNodes*.childNodes[0].childNodes[j].childNodes[k].attributes.speaker, this.firstChild.childNodes[2].childNodes*.childNodes[0].childNodes[j].childNodes[k].firstChild.nodeValue, i+1, j+1, {ra:100, rb:200, ga:100, gb:20, ba:100, bb:123, aa:100, ab:0}, 0, -100, 100, 200, 200);
speechArray.splice(arrayVar, 0, mainArray*[j][k]);
arrayVar++;
}
}
}
}
trace(speechArray[0].getspeaker());
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("roj-play.xml");
I can trace the Array from inside the loadXML function, but not outside it, which is what I want to do. I have read Senocular’s XML specificIssues3 page, and tried the suggestions, but I am not sure which is the best one to use, and how exactly they apply to my specific problem. Any suggestions would be greatly appreciated.
you’re tracing the variable before its defined. The onLoad event occurs after all the code in that script has been executed. Its purpose for existing is because it takes time to load external information. You cant access a variable defined in an onLoad prior to when the onLoad is fired.