0 Replies Latest reply on Apr 14, 2010 11:59 AM by armandix

    xml conection

    armandix

      hi , i I wrote the following code for a quiz game :


      function QuizItem(question)
      {
          this.question = question;
          this.answers = new Array();
          this.numOfAnswers = 0;
          this.correctAnswer = 0;
          this.getQuestion = function ()
          {
             
          
              return (this.question);
          };
         
          this.addAnswer = function (answer, isCorrectAnswer)
          {
             
              this.answers[this.numOfAnswers] = answer;
              if (isCorrectAnswer)// ver se a mesma é a correcta
              {
                  this.correctAnswer = this.numOfAnswers; //para uma pergunta correcta existe uma resposta certa
              } // end if
              ++this.numOfAnswers;
          };
          this.getAnswer = function (answerNumberToGet)
          {
              return (this.answers[answerNumberToGet]);
          };
          this.getCorrectAnswerNumber = function ()
          {
              return (this.correctAnswer);
          };
          this.checkAnswerNumber = function (userAnswerNumber)
          {
              if (userAnswerNumber == this.getCorrectAnswerNumber())
              {
                  gotoAndPlay(19);
              }
              else//se for uma resposta errada vai para a frame 20
              {
                  gotoAndPlay(20);
              } // end else if
          };
          this.getNumOfAnswers = function ()
          {
              return (this.answers.length);//resposta em numero
          };
      } // End of the function
      function onQuizData(success)//caso o data quiz seja carregado com sucesso
      {
          var quizNode = this.firstChild;
          var quizTitleNode = quizNode.firstChild;
          title = quizTitleNode.firstChild.nodeValue;
          var i = 0;// o numero complexo i=0
          var itemsNode = quizNode.childNodes[1];
          while (itemsNode.childNodes[i])
          {
              var itemNode = itemsNode.childNodes[i];
              var questionNode = itemNode.childNodes[0];
              quizItems[i] = new QuizItem(questionNode.firstChild.nodeValue);
              var a = 1;
              var answerNode = itemNode.childNodes[a++];
              while (answerNode)
              {
                  var isCorrectAnswer = false;
                  if (answerNode.attributes.correct == "y")
                  {
                      isCorrectAnswer = true;
                  } // end if
                  quizItems[i].addAnswer(answerNode.firstChild.nodeValue, isCorrectAnswer);
                  answerNode = itemNode.childNodes[a++];
              } // end while
              ++i;
          } // end while
          gotoAndPlay(_currentframe + 1);
      } // End of the function
      var quizItems = new Array();
      var myData = new XML();
      myData.ignoreWhite = true;
      myData.onLoad = onQuizData;
      myData.load("questionario/questionario.xml");
      stop ();

       

      -//--

      I'd like to put a picture on each question.
      someone can help me, tanks