How do I compare an array value in an if statement
When I compare cdlCorrect[index] to 0, it shows true, but when I trace it, it shows 2.
The if statement seems to be comparing the index itself to 0. How do I make it compare the value. In fact, as I keep calling this function (clicking the button), it always compares to 0, but the trace will come back as 2, then 1, then 2, then 0, then 0. I would think I am getting the index, but then it should compare to 0, then 1, then 2 etc. I do not understand why it always compares with zero.
function chkAnswer(mevt:MouseEvent):void {
cdlDone[index] = 1;
var rectSize:uint = 300;
var correctRect:Shape = new Shape();
correctRect.graphics.beginFill(0x00FF00, 0.5);
if (cdlCorrect[index] == 0) {
correctRect.graphics.drawRect(45, 40, rectSize, 30); //coordinates: 45:x 120:y rectSize:width 50:height
trace("This is 0");
}
if (cdlCorrect[index] == 1) {
correctRect.graphics.drawRect(45, 80, rectSize, 30); //coordinates: 45:x 120:y rectSize:width 50:height
trace("This is 1");
}
if (cdlCorrect[index] == 2) {
correctRect.graphics.drawRect(45, 80, rectSize, 30); //coordinates: 45:x 120:y rectSize:width 50:height
trace("This is 2");
}
trace(cdlCorrect[index]); // 2
trace(cdlCorrect); // 2,1,2,0,0
}
