PDA

View Full Version : [MX2004] Array issues



sarah012
May 13th, 2004, 08:28 AM
I have created two arrays from XML the first array (QuestionArray) contains the second array (AnswersArray). The answers to each question in the XML are:
Question 1
-True
-False

Question 2
-Hartford
-Bloomfield
-New Haven
-Washington D.C

But when I trace the answers in my array I get:

True, False

Washington D.C, Bloomfield, New Haven, Washington D.C

Here's my code:


function buildQuestionArray() {
_global.QuestionsArray = new Array ()
for (var i=0; i<TestNode.childNodes.length; i++){
curQuestion=TestNode.childNodes[i];
var AnswersArray = new Array();
for (var j=0; j<curQuestion.childNodes.length; j++){
curParts=curQuestion.childNodes[j];
for (var b=0; b<curParts.childNodes.length; b++){
if (curParts.childNodes[b].nodeName==null){
curImage=curParts.childNodes[b];
}else if (curParts.childNodes[b].nodeName!=null){
curImage=null;
curAnswers=curParts.childNodes[b];
}
AnswersArray[b]= curAnswers.childNodes
}
}
_global.QuestionsArray[i] = new Question (curQuestion.attributes.number, curQuestion.attributes.format, curQuestion.attributes.correctanswer, curQuestion.attributes.text, curImage, AnswersArray)
}
makeQuestion (currentQuestion);
ClickTrue (currentQuestion);
}

function Question (numbers, format, correct, Text, Image, Answers) {
this.numbers=numbers
this.correct=correct
this.Text=Text
this.format=format
this.Image=Image
this.Answers=Answers
trace (Answers)

}[/QUOTE]

Fam
May 13th, 2004, 09:15 AM
Have you tried looking at how the Array is being stored inside the authoring environment? Ctrl-Alt-V will bring up the List Variable panel, I find it more accurate than traces.

sarah012
May 13th, 2004, 09:56 AM
Interesting...
This is what I got:

Variable _global.QuestionsArray = [object #8, class 'Array'] [
0:[object #9, class 'Question'] {
numbers:"1 of 5",
Correct:"2",
Text:"The capital of Connecticut is Bloomfield",
format:"1",
Image:null,
Answers:[object #10, class 'Array'] [
0:[object #11, class 'Array'] [
0:[object #12, class 'XMLNode'] {
True
}
],
1:[object #13, class 'Array'] [
0:[object #14, class 'XMLNode'] {
False
}
]
]
},
1:[object #15, class 'Question'] {
numbers:"2 of 5",
Correct:"1",
Text:"What is the capital of Connecticut?",
format:"2",
Image:[object #16, class 'XMLNode'] {
CTMap.jpg
},
Answers:[object #17, class 'Array'] [
0:[object #18, class 'Array'] [
0:[object #19, class 'XMLNode'] {
Washington D.C.
}
],
1:[object #20, class 'Array'] [
0:[object #21, class 'XMLNode'] {
Bloomfield
}
],
2:[object #22, class 'Array'] [
0:[object #23, class 'XMLNode'] {
New Haven
}
],
3:[object #18, class 'Array']
]
},

Washington DC, should be #3 in the array, not number one. Any idea whats going on?