I desire is quick/easy to solve, but I'm stuck AS problem 3

I thought I would teach my 10th grade class programming Action Script 3.0. We already crossed SmallBasic and they include conditional logic, loop etc... you give a little background so I thought we we Landa it in OBJECT-oriented programming language.

I have not touched A.S. Since back in 2.0 and I think I'm missing something. I used this tutorial as a foundation and updated to reflect the AS3.0 for my lecture notes.

That said, when you do their quiz, (a quiz 2 simple question that counts the score at the end of the quiz) I get an error of logic. Everything works without problems using the controls, I get variables back properly to the part of the interpreter, but the logical evaluation end returns a glitch where it counts against my last value clicked and uses two times to evaluate the truth. Probably I'm missing something simple and it'll take someone who knows Flash well about 3 seconds to ID my problem.

Thanks in advance.

FLA file you wish to browse:

FLA file

SWF file if you want to display only:

SWF file

If you don't want to dload files so here AS code at 3 locations (q1, q2, quizEnd)

Code block 1 to frame 1:

Initialize main timeline variables

Then create variables to store user responses:

var q1Answer;          The user in question 1 answer

var q2Answer;          User for question 2's answer

Then, create a variable to track the number of questions answered correctly:

var totalCorrect = 0;  Number of counts of correct answers

Finally, stop the movie at the first question:

Stop();

choice1_btn.addEventListener (MouseEvent.CLICK, answer1);

function answer1(event_object:MouseEvent) {}

q1Answer = 1;

gotoAndStop ("q2");

trace (q1Answer);

}

choice2_btn.addEventListener (MouseEvent.CLICK, answer2);

function answer2(event_object:MouseEvent) {}

q1Answer = 2;

gotoAndStop ("q2");

trace (q1Answer);

}

choice3_btn.addEventListener (MouseEvent.CLICK, answer3);

function answer3(event_object:MouseEvent) {}

q1Answer = 3;

gotoAndStop ("q2");

trace (q1Answer);

}

Code 2 block to frame 10

choice1_btn.addEventListener (MouseEvent.CLICK, answer21);

function answer21(event_object:MouseEvent) {}

q2Answer = 1;

gotoAndStop ("quizEnd");

trace (q2Answer);

}

choice2_btn.addEventListener (MouseEvent.Click, answer22);

function answer22(event_object:MouseEvent) {}

q2Answer = 2;

gotoAndStop ("quizEnd");

trace (q2Answer);

}

choice3_btn.addEventListener (MouseEvent.Click, answer23);

function answer23(event_object:MouseEvent) {}

q2Answer = 3;

gotoAndStop ("quizEnd");

trace (q2Answer);

}

Code Block 3 to 20 frame

If (q1Answer == 3) {}

totalCorrect = totalCorrect + 1;

trace ("value of Q1 is 1 point");

} else {}

trace ("Wrong answer #1" + q1Answer);

}

If (q2Answer == 3) {}

totalCorrect ++; Simply adds to the previous value of the totalCorrect 1.

trace ("value of Q2 is 1 point");

} else {}

trace ("Wrong answer #2" + q2Answer);

}

final score displayed on interpreter

trace ("your total is" + totalCorrect + "/ 2 points");

Displays the response on the stage

var txtFld:TextField = new TextField();

addChild (txtFld);

txtFld.text = ("your total is" + totalCorrect);

txtFld.appendText (' / 2 points ");

extra bits to comment out text is included

txtFld.wordWrap = true;

txtFld.textColor = 0xFF00FF

txtFld.width = 150

txtFld.height = 60

Oh I see the problem.

you use the same names of button for q1 and q2 and you delete not all listeners.  You must fix this.

Tags: Adobe Animate

Similar Questions

Maybe you are looking for