Hi this is my first attempt at using actionscript 3 so if you could help me I would be grateful.
Basically I am trying to load an xml document and when it has loaded loop through and assign to array using the for loop but I am getting this error
“TypeError: Error #1009: Cannot access a property or method of a null object reference.
at quiz_fla::MainTimeline/ParseQuestions()
at quiz_fla::MainTimeline/LoadXML()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()”
Here is my code
stop();
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("quiz.xml"));
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
ParseQuestions(xmlData);
}
var correct:String;
var score:int= 0;
var userAnswer:String;
var questionArray:Array;
// or you can iterate through the xml entity
function ParseQuestions(questionInput:XML):void {
for (var i:int =0;i<10;i++){
questionArray[i] = questionInput.question[i].answer[i].text();
questionArray[i][0] = questionInput.question[i].answer[0].text();
questionArray[i][1] = questionInput.question[i].answer[1].text();
questionArray[i][2] = questionInput.question[i].answer[2].text();
}
}