hannahd
06-14-2005, 08:39 PM
Hello,
I have written a class for loading questions from an xml file.
My problem is with the process method which is called when the XML file is loaded. Trace displays the content of the xml file when I put trace(this), so 'this' means the xml object, but when I ask for the firstChild of this, it says it is not a property of it.
Please help!
Hannah
class QuizXMLLoader {
private var xmlobj:XML;
private var quiz_url:String;
private var questions:Array;
function QuizXMLLoader(quiz_url:String) {
this.quiz_url = quiz_url;
xmlobj = new XML();
xmlobj.load(quiz_url);
xmlobj.ignoreWhite = true;
xmlobj.onLoad = process;
questions = new Array();
}
function process(success:Boolean) {
trace(this);
//var question_nodes:Array = this.firstChild.childNodes;
//for(var i=0; i<question_nodes.length; i++) {
//var question_node:XMLNode = question_nodes[i];
//var fields = question_node.childNodes;
//var question_text:String = String(fields[0].firstChild);
//var answer_nodes:Array = fields[1].childNodes;
//var answers:Array = new Array();
//for(var j=0; j<answer_nodes.length; j++) {
//answers.push(String(answer_nodes[j].firstChild));
//}
//var correct_answer = Number(String((fields[2].firstChild)));
//var answer1 = answers[0];
//var answer2 = answers[1];
//var answer3 = answers[2];
//var answer4 = answers[3];
//var q = new Question(question_text, answer1, answer2, answer3, answer4, correct_answer);
//questions.push(q);
//}
}
}
I have written a class for loading questions from an xml file.
My problem is with the process method which is called when the XML file is loaded. Trace displays the content of the xml file when I put trace(this), so 'this' means the xml object, but when I ask for the firstChild of this, it says it is not a property of it.
Please help!
Hannah
class QuizXMLLoader {
private var xmlobj:XML;
private var quiz_url:String;
private var questions:Array;
function QuizXMLLoader(quiz_url:String) {
this.quiz_url = quiz_url;
xmlobj = new XML();
xmlobj.load(quiz_url);
xmlobj.ignoreWhite = true;
xmlobj.onLoad = process;
questions = new Array();
}
function process(success:Boolean) {
trace(this);
//var question_nodes:Array = this.firstChild.childNodes;
//for(var i=0; i<question_nodes.length; i++) {
//var question_node:XMLNode = question_nodes[i];
//var fields = question_node.childNodes;
//var question_text:String = String(fields[0].firstChild);
//var answer_nodes:Array = fields[1].childNodes;
//var answers:Array = new Array();
//for(var j=0; j<answer_nodes.length; j++) {
//answers.push(String(answer_nodes[j].firstChild));
//}
//var correct_answer = Number(String((fields[2].firstChild)));
//var answer1 = answers[0];
//var answer2 = answers[1];
//var answer3 = answers[2];
//var answer4 = answers[3];
//var q = new Question(question_text, answer1, answer2, answer3, answer4, correct_answer);
//questions.push(q);
//}
}
}