AS3测验 - 如何进入下一个问题?

时间:2009-09-28 19:25:22

标签: actionscript-3 flash flash-cs3

使用各种教程我在AS3中创建了下一个测验。它是动态的,我使用一个重要的功能来设置整个事物,并使用一个计数器来管理测验和数组。 选择答案后,单击复选按钮,然后单击“下一步”按钮。 我没有错误,但由于某种原因调用setup()函数没有移动测验fwd。 附上我的短代码,编辑无用的东西,我会喜欢一些建议。 顺便说一下,外语是希伯来语:)

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 个答案:

答案 0 :(得分:4)

变化:

function setup():void {

var i:Number=0;

为:

var i:Number=0;

function setup():void {

否则,你用'i ++'递增并调用'setup()',然后再将'i'重置为0并且增量从未发生过。

P.S。使用“代码示例”格式化将极大地帮助您的示例的可读性。