0

使用各种教程,我在 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();

 }
}
4

1 回答 1

4

改变:

function setup():void {

var i:Number=0;

至:

var i:Number=0;

function setup():void {

否则,您将使用“i++”递增并调用“setup()”,然后将“i”再次重置为 0,并且从未发生过递增。

PS 使用“代码示例”格式将极大地提高示例的可读性。

于 2009-09-28T19:38:03.303 回答