PDA

View Full Version : it works during trace, but not as a var


Tokidoki
06-18-2008, 09:36 PM
I'm trying to make an interactive quiz. depending on what the answers is chosen, itll bring to a another specific question. Each answer has a certain value (1,2,3,4,5,etc)

and I record the value via xml through this code


arrAGoTo[i] = new Array();
for (j=0; j<dataXML.question[i].answers.length(); j++) {
arrAGoTo[i][j] = dataXML.question[i].answers[j].@goTo.toString();
}


so as you can see all the value is recorded at:
arrAGoTo[i][j]

i being the question number and j being the answer selected

it will then be passed to the following function as:
arrAGoTo[index-1][rbg.selectedData]


btnCheck.addEventListener(MouseEvent.CLICK, chkAnswer);
function chkAnswer(mevt:MouseEvent):void {
index=index+arrAGoTo[index-1][rbg.selectedData];
trace(arrAGoTo[index-1][rbg.selectedData]);
setup();
}


the trace for arrAGoTo[index-1][rbg.selectedData] works. It gives the value that I want on the output window. but when I assign it to index, it gives me the following error message:

TypeError: Error #1010: A term is undefined and has no properties.
at oce_coding_experiment_v1_fla::MainTimeline/chkAnswer()


Help!

tukinu
06-19-2008, 06:46 AM
just as an idea. check the datatyps of your vars. maybe one is a number and the other a string.

Tokidoki
06-19-2008, 12:34 PM
i inserted this code
var goTo:Number = arrAGoTo[index-1][rbg.selectedData];
and replace index to index = goTo;
and it still doesnt work
hm.. it seems that the problem is in the arrAGoto[][]

thanks!

lordofduct
06-19-2008, 12:58 PM
run this:

btnCheck.addEventListener(MouseEvent.CLICK, chkAnswer);
function chkAnswer(mevt:MouseEvent):void {
index=index+arrAGoTo[index-1][rbg.selectedData];
trace(index, arrAGoTo.length);
if (arrAGoTo[index-1]) trace (rbg.selectedData , arrAGoTo[index-1]);
}


if only one thing traces, that means that index is out of the range of the Array.
if both trace, then check the second traces values. If the first value is >= to the second value, then it is out of the range. If everything is in range, then make sure that rbg.selectedData is a Number and not a string. Sometimes there are type casting issues.

I don't know what you have index or rbg.selectedData typed as, because you didn't supply that code.

Tokidoki
06-19-2008, 02:01 PM
thanks for helping me solve this problem!

all I had to do is re arrange the code

arrAGoTo[index-1][rbg.selectedData] must be before the "index =" code
thanks!