Actionscript 3 创建MCQs考试时,Actionscript 3中的分数计数器出现错误
我要做一个计数器来计算考试题的正确答案。 计数器将仅从每个帧收集正确答案 这是第一帧:Actionscript 3 创建MCQs考试时,Actionscript 3中的分数计数器出现错误,actionscript-3,Actionscript 3,我要做一个计数器来计算考试题的正确答案。 计数器将仅从每个帧收集正确答案 这是第一帧: 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
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();
第二帧是:
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();
所有其他帧将作为第二帧
我想知道哪里错了。你的一般方法在这里是错误的&你的游戏不是很好扩展。你需要对你的游戏做一个概述,并尝试提出一个更好的逻辑 您可以在侦听器中标识一个按钮,这样就不需要添加这么多事件侦听器,一个就可以了。确定单击的按钮并相应地设置答案
function clickHandler(event:MouseEvent):void
{
trace( event.currentTarget);
}
如果将所有按钮放在一个数组中,则可以轻松设置它们的alpha属性
var buttons:Array = [ans1_mc, ans2_mc, ans3_mc , ans4_mc];
function clickHandler(event:MouseEvent):void
{
//set all buttons alpha to 0
for each( var button:MovieClip in buttons )
button.alpha = 0;
//set the alpha of the clicked button to 1
event.currentTarget.alpha = 1;
//set the correct answer
if( event.currentTarget == ans1_mc )
correctAns = 1;
}
我还没有测试过你的代码,所以我不确定有多少错误,在任何情况下,你都应该像上面那样在函数中设置correctAns变量。非常感谢。我会尝试你的代码,然后回来给你反馈。一般来说,这不是我真正需要的,但这并不意味着你没有帮助我,你做了一件很好的工作,帮助我使用一种好的方法来实现我的目标。谢谢