1 Reply Latest reply on Jun 13, 2008 3:42 PM by FlashTastic

    Loading XML into flash

    Caly2007
      I'm a beginner in programming I have been having problems loading xml files into a blank

      look at the code I have written and give me pointers.

      import mx.xpath.XPathAPI;

      var aQuiz:Array = new Array();
      var xmlQuiz:XML = new XML();
      xmlQuiz.ignoreWhite = true;
      xmlQuiz.load("questions.xml");
      xmlQuiz.onLoad = function() {
      var question:Array = XPathAPI.selectNodeList(xmlQuiz.firstChild, "*/text");
      for (var i:Number = 0; i<question.length; i++) {
      var quizNode:XMLNode = question ;
      var quiz:Object = new Object();

      quiz.id = quizNode.attributes.id;
      quiz.text = XPathAPI.selectSingleNode(quizNode, "*/text").firstChild.nodeValue;

      aQuiz.push(quiz);
      }
      gotoAndStop("Initial");
      };

      function display ():Void{
      var textquestions:String = "";
      for (var i:Number=0; i<aQuiz.length; i++){
      var quiz:Object = aQuiz
      ;
      textquestions += +quiz.id+"."+" "+quiz.text;
      }
      txt_question.html = true;
      txt_question.text = textquestions;

      the xml file looks like this

      <questions>
      <question id="1">
      <text>Which of the following computer components can be safely disposed of in regular trash?</text>
      <answers>
      <answer>Monitor</answer>
      <answer>Printer toner</answer>
      <answer>Laptop batteries</answer>
      <answer correct="true">None of the above</answer>
      </answers>
      </question>

      <question id="2">
      <text>What key do you press to access Safe Mode when Windows 98 is booting?</text>
      <answers>
      <answer>F1</answer>
      <answer>F2</answer>
      <answer>F6</answer>
      <answer correct="true">F8</answer>
      </answers>
      </question>

      </questions>

      can some one tell me what is wrong in my code that it can not display?