I'm going to make a counter that will count the correct answers of an exam questions. The counter will collect only the correct answers from each frame.
Here is the first frame:
var counter:Number = 0;
var correctAns:Number;
correctAns = ans1_mc.alpha;
function clicked1(event:MouseEvent):void
{
ans1_mc.alpha = 1;
ans2_mc.alpha = 0;
ans3_mc.alpha = 0;
ans4_mc.alpha = 0;
}
function clicked2(event:MouseEvent):void
{
ans1_mc.alpha = 0;
ans2_mc.alpha = 1;
ans3_mc.alpha = 0;
ans4_mc.alpha = 0;
}
function clicked3(event:MouseEvent):void
{
ans1_mc.alpha = 0;
ans2_mc.alpha = 0;
ans3_mc.alpha = 1;
ans4_mc.alpha = 0;
}
function clicked4(event:MouseEvent):void
{
ans1_mc.alpha = 0;
ans2_mc.alpha = 0;
ans3_mc.alpha = 0;
ans4_mc.alpha = 1;
}
function submit(event:MouseEvent):void
{
if (correctAns == 1)
{
counter++;
}
else
{
counter = counter;
}
trace (counter);
gotoAndStop(currentFrame + 1);
}
ans1_btn.addEventListener(MouseEvent.CLICK, clicked1);
ans2_btn.addEventListener(MouseEvent.CLICK, clicked2);
ans3_btn.addEventListener(MouseEvent.CLICK, clicked3);
ans4_btn.addEventListener(MouseEvent.CLICK, clicked4);
submit_btn.addEventListener(MouseEvent.CLICK, submit);
ans1_mc.alpha = 0;
ans2_mc.alpha = 0;
ans3_mc.alpha = 0;
ans4_mc.alpha = 0;
text1_txt.text = "A";
text2_txt.text = "B";
text3_txt.text = "C";
text4_txt.text = "D";
stop();
The Second Frame is:
ans1_mc.alpha = 0; ans2_mc.alpha = 0; ans3_mc.alpha = 0; ans4_mc.alpha = 0;
correctAns = ans1_mc.alpha;
text1_txt.text = "E";
text2_txt.text = "F";
text3_txt.text = "G";
text4_txt.text = "H";
stop();
All other frames will be as the second frame.
I want to know where is the wrong.