1 Reply Latest reply on Oct 11, 2006 1:16 AM by Thepoor13

    Array

    Thepoor13 Level 1
      can array store Numberic data
      and is my code wrong?
      //Loading Data
      var total:Number;
      //Number of questions selected
      loadVariablesNum("Some.txt", 0);
      var Question:Array = new Array();
      var Answer1:Array = new Array();
      var Answer2:Array = new Array();
      var Answer3:Array = new Array();
      var Answer4:Array = new Array();
      var CorrectAnswer:Array = new Array();
      function loadDataintoArray() {
      total = 1;
      while (eval("Q"+total) != undefined) {
      Question[total] = eval("Q"+total);
      Answer1[total] = eval("A1"+total);
      Answer2[total] = eval("A2"+total);
      Answer3[total] = eval("A3"+total);
      Answer4[total] = eval("A4"+total);
      CorrectAnswer = eval("CA"+total);
      trace(Question[total]);
      trace(Answer1[total]);
      trace(Answer2[total]);
      trace(Answer3[total]);
      trace(Answer4[total]);
      total += 1;
      }
      total -= 1;
      }
      this.onData = function() {
      loadDataintoArray();
      Randommize();
      //Question_txt.text = Question[SelectedQuestion[1]];
      //Opt1.label = Answer1[SelectedQuestion[1]];
      //Opt2.label = Answer2[SelectedQuestion[1]];
      //Opt3.label = Answer3[SelectedQuestion[1]];
      //Opt4.label = Answer4[SelectedQuestion[1]];
      };
      //Check Student' answer
      var StudentAnswer:Array = new Array(5);
      function checkAnswer() {
      if ((Opt1.value == false) and (Opt1.value == false) and (Opt1.value == false) and (Opt1.value == false)) {
      Error_txt.text = "Cha chän c©u tr¶ lêi";
      } else {
      if (Opt1.value == true) {
      StudentAnswer[NextQuestion] = 1;
      }
      if (Opt2.value == true) {
      StudentAnswer[NextQuestion] = 2;
      }
      if (Opt3.value == true) {
      StudentAnswer[NextQuestion] = 3;
      }
      if (Opt4.value == true) {
      StudentAnswer[NextQuestion] = 4;
      }
      }
      }
      //load next Question
      var NextQuestion:Number = 1;
      function loadNextquestion() {
      if (NextQuestion<=5) {
      Question_txt.text = Question[SeclectedQuestion[NextQuestion]];
      Opt1.label = Answer1[SeclectedQuestion[NextQuestion]];
      Opt2.label = Answer2[SeclectedQuestion[NextQuestion]];
      Opt3.label = Answer3[SeclectedQuestion[NextQuestion]];
      Opt4.label = Answer4[SeclectedQuestion[NextQuestion]];
      }
      }
      //Randommize the question
      var SeclecteQuestion:Array = new Array(0, 0, 0, 0, 0);
      function checkSeclectedQuestion(n:Number):Boolean {
      for (i=1; i<=5; i++) {
      if (SeclectedQuestion
      == n) {
      return true;
      }
      }
      return true;
      }
      //Randommize 5 question in total
      function Randommize() {
      j = 1;
      var n:Number;
      while (j<=5) {
      n = random(total);
      if (checkseclectedQuestion(n) == false) {
      SeclectedQuestion[j] = n;
      j += 1;
      }
      }
      }
      //Main funtion
      this.Confirm_btn.onRelease = function() {
      if (checkAnswer()) {
      loadNextquestion();
      }
      };