Need help finding what is wrong with this code. It seem to work fine getting the array “arr” based on the SharedObject variables and picks only the ones with the value = 1. But when it gets to the function randArray(), all elements become “unidentified”:
score = 0;
arr = [];
id = 0;
count = 0;
_xml = new XML();
_xml.ignoreWhite = true;
_xml.load("words.xml");
wordArray = [];
_xml.onLoad = function() {
cNodes = this.firstChild.childNodes;
len = cNodes.length;
for (var n = 0; n != len; n++) {
obj = {};
obj.Word = cNodes[n].attributes['theWord'];
obj.Meaning = cNodes[n].attributes['theMeaning'];
wordArray.push(obj);
}
showText(0);
arr = new Array();
for (n=0; n<len; n++) {
if (savedTexts.data["var"+n] == 1) {
arr.push(Word=wordArray[n].Word, Meaning=wordArray[n].Meaning);
}
}
trace(arr); // this shows elements chosen based on SO savetext
wordArray = arr;
randArray();
};
savedTexts = SharedObject.getLocal("savetext", "/");
function randArray() {
arr.sort(function () {
return Math.floor(Math.random()*3)-1;
});
for (var n = 0; n != arr.length; n++) {
trace("arr["+n+"].theWord = "+arr[0].Word); //these 2 unidentified
trace("arr["+n+"].theMeaning = "+arr[0].Meaning+newline);
}
askQuestion(id);
}
Any input is appreciated.