Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getAllQuestions(){
  2.     //retrieves and holds XML content
  3.  
  4.     var test:XML; //holds an instance of the XML class
  5.     var loader:URLLoader = new URLLoader(); //holds an instance of the URLLoader class
  6.  
  7.     loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
  8.     loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
  9.  
  10.     loader.load(new URLRequest("test.xml")); //loads XML
  11.  
  12.     function onComplete(evt:Event):void {
  13.         try {
  14.             test=new XML(evt.target.data);
  15.             //trace(test); //testing xml file
  16.             loader.removeEventListener(Event.COMPLETE, onComplete);
  17.             loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
  18.         } catch (err:Error) {
  19.         trace("Could not parse loaded content as XML:\n" + err.message);
  20.     }
  21. }
  22.  
  23. //On error trying to retieve xml file
  24. function onIOError(evt:IOErrorEvent):void {
  25.     trace ("an error ocured when attempting to load the XML.\n" + evt.text);
  26. }
  27.    
  28.     //get all the questions from xml
  29.     var question1:String = test.questions.questionAnswers1.question;
  30.     var question2:String = test.questions.questionAnswers2.question;
  31.     var question3:String = test.questions.questionAnswers3.question;
  32.     var question4:String = test.questions.questionAnswers4.question;
  33.     var question5:String = test.questions.questionAnswers5.question;
  34.     var question6:String = test.questions.questionAnswers6.question;
  35.     var allQuestions:Array = [question1, question2, question3, question4,
  36.                                                    question5, question6]; //storing all questions from XML file
  37.     return allQuestions;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement