AS3 测验 - 如何转到下一个问题?
使用各种教程,我在 AS3 中创建了下一个测验。它是动态的,我使用一个重要的函数来设置整个事物,并使用一个计数器来管理测验和数组。 选择答案后,单击复选按钮,然后单击“下一步”按钮。 我没有收到任何错误,但是由于某种原因,调用 setup() 函数并没有移动测验。 附件是我的简短代码,其中包含对无用内容的编辑,我希望得到一些建议。 顺便说一句,外语是希伯来语:)
var arrQuestion:Array = [ "?מיהו סטיב ג'ובס", "מהי משמעות הקיצור WWW?"];
var arrAnswers:Array = [["AOL מנכל","יור אורקל","מנכל אפל","מנכל סאן"], ["World Wide Web", "With Web Wins", "Wired Web Window", "Wap Windows War"]];
var arrCorrect:Array = [3, 1];
var btnNext:myNext = new myNext();
setup();
function setup():void {
var i:Number=0;
var thequestion_txt:TextField= new TextField;
addChild(thequestion_txt);
var feedback_txt:TextField= new TextField;
addChild(feedback_txt);
var radio1:RadioButton = new RadioButton();
var radio2:RadioButton = new RadioButton();
var radio3:RadioButton = new RadioButton();
var radio4:RadioButton = new RadioButton();
var radioGrp:RadioButtonGroup = new RadioButtonGroup("radioGrp");
addChild(radio1);
addChild(radio2);
addChild(radio3);
addChild(radio4);
radio1.label = arrAnswers[i][0];
radio1.value = 1;
//etc..
var checkButton:Button = new Button();
addChild(checkButton);
checkButton.x =230;
checkButton.y = 300;
checkButton.label = "בדוק";
checkButton.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
addChild(btnNext);
btnNext.x =230;
btnNext.y = 300;
if (radioGrp.selection.value == (arrCorrect[i])) {
feedback_txt.text = "!נכון מאוד";
btnNext.addEventListener(MouseEvent.CLICK, myRemove);
} else {
feedback_txt.text = "תשובה שגויה";
btnNext.addEventListener(MouseEvent.CLICK, myRemove);
}
}
function myRemove(e:MouseEvent):void {
removeChild(thequestion_txt);
removeChild(feedback_txt);
removeChild(radio1);
removeChild(radio2);
removeChild(radio3);
removeChild(radio4);
removeChild(checkButton);
removeChild(btnNext);
//chaning the counter to change the question and answers
i++;
//shouldn't the call to setting up the entire stage again be here?
//it is't working, I dont get the next question.
setup();
}
}
using various tutorials I created the next quiz in AS3. It's dynamic and I use an important function to set up the entire thing, and a counter to manage the quiz and arrays.
After picking an answer you click on a check button and then on a "Next" button.
I'm getting no errors, however for some reason calling the setup() function isn't moving the quiz fwd.
Attached is my short code with edits of the useless stuff, I would love some suggestions.
BTW, the foreign language is Hebrew :)
var arrQuestion:Array = [ "?מיהו סטיב ג'ובס", "מהי משמעות הקיצור WWW?"];
var arrAnswers:Array = [["AOL מנכל","יור אורקל","מנכל אפל","מנכל סאן"], ["World Wide Web", "With Web Wins", "Wired Web Window", "Wap Windows War"]];
var arrCorrect:Array = [3, 1];
var btnNext:myNext = new myNext();
setup();
function setup():void {
var i:Number=0;
var thequestion_txt:TextField= new TextField;
addChild(thequestion_txt);
var feedback_txt:TextField= new TextField;
addChild(feedback_txt);
var radio1:RadioButton = new RadioButton();
var radio2:RadioButton = new RadioButton();
var radio3:RadioButton = new RadioButton();
var radio4:RadioButton = new RadioButton();
var radioGrp:RadioButtonGroup = new RadioButtonGroup("radioGrp");
addChild(radio1);
addChild(radio2);
addChild(radio3);
addChild(radio4);
radio1.label = arrAnswers[i][0];
radio1.value = 1;
//etc..
var checkButton:Button = new Button();
addChild(checkButton);
checkButton.x =230;
checkButton.y = 300;
checkButton.label = "בדוק";
checkButton.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
addChild(btnNext);
btnNext.x =230;
btnNext.y = 300;
if (radioGrp.selection.value == (arrCorrect[i])) {
feedback_txt.text = "!נכון מאוד";
btnNext.addEventListener(MouseEvent.CLICK, myRemove);
} else {
feedback_txt.text = "תשובה שגויה";
btnNext.addEventListener(MouseEvent.CLICK, myRemove);
}
}
function myRemove(e:MouseEvent):void {
removeChild(thequestion_txt);
removeChild(feedback_txt);
removeChild(radio1);
removeChild(radio2);
removeChild(radio3);
removeChild(radio4);
removeChild(checkButton);
removeChild(btnNext);
//chaning the counter to change the question and answers
i++;
//shouldn't the call to setting up the entire stage again be here?
//it is't working, I dont get the next question.
setup();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改
为
:否则,您将使用“i++”递增并调用“setup()”,然后再次将“i”重置为 0,并且增量从未发生。
PS 使用“代码示例”格式将极大地提高示例的可读性。
change:
to:
Otherwise, you're incrementing with 'i++' and calling 'setup()', which then resets 'i' to 0 again and the increment never happened.
P.S. using 'Code Sample' formatting would help the readability of your example immensely.