0
使用各種教程我在AS3中創建了下一個測驗。它是動態的,我使用一個重要的函數來設置整個事物,並且使用一個計數器來管理測驗和數組。 挑選答案後,點擊選中按鈕,然後點擊「下一步」按鈕。 我沒有收到任何錯誤,但是由於某種原因,調用setup()函數不會移動測驗fwd。 附加是我的短代碼編輯的無用的東西,我會喜歡一些建議。 BTW,外語是希伯來語:)AS3測驗 - 如何轉到下一個問題?
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();
}
}
+1代碼格式化評論 - 這真的會大大增加可讀性 – Cameron
卡梅隆,謝謝你的回答,我試了一下,它的工作! 我確實使用了代碼示例格式,但我想在我的編輯後出現了一個小故障,並沒有奏效。 謝謝! – Sarit