Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getAllQuestions(){
- //retrieves and holds XML content
- var test:XML; //holds an instance of the XML class
- var loader:URLLoader = new URLLoader(); //holds an instance of the URLLoader class
- loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
- loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
- loader.load(new URLRequest("test.xml")); //loads XML
- function onComplete(evt:Event):void {
- try {
- test=new XML(evt.target.data);
- //trace(test); //testing xml file
- loader.removeEventListener(Event.COMPLETE, onComplete);
- loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
- } catch (err:Error) {
- trace("Could not parse loaded content as XML:\n" + err.message);
- }
- }
- //On error trying to retieve xml file
- function onIOError(evt:IOErrorEvent):void {
- trace ("an error ocured when attempting to load the XML.\n" + evt.text);
- }
- //get all the questions from xml
- var question1:String = test.questions.questionAnswers1.question;
- var question2:String = test.questions.questionAnswers2.question;
- var question3:String = test.questions.questionAnswers3.question;
- var question4:String = test.questions.questionAnswers4.question;
- var question5:String = test.questions.questionAnswers5.question;
- var question6:String = test.questions.questionAnswers6.question;
- var allQuestions:Array = [question1, question2, question3, question4,
- question5, question6]; //storing all questions from XML file
- return allQuestions;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement