views:

300

answers:

1

Hello, 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();

 }
}
+4  A: 

change:

function setup():void {

var i:Number=0;

to:

var i:Number=0;

function setup():void {

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.

JStriedl
+1 for code formatting comment -- it really would drastically increase the readability
Cameron
Cameron, thank you for your answer, I tried it and it's working!I did use the Code Sample formatting but I guess there was a glitch in my editing afterwards and it didn't work.Thanks!
Sarit