Hi there.

I am a Java programmer who is not new to Flash. I am extending an application written in AS2, so unfortunately can't use AS3 (whose XML loading is obviously superior). It is a quiz that builds itself out of an XML document.

I am having problems loading my XML inside an external class that I am creating. When I do the exact same thing in a movie clip it works fine, but as soon as I move the code to a self defined object it returns 'undefined' when I trace the XML object.

Is there something I'm missing? Here is a code sample. Some of the objects defined are my own. I've commented them out so I can be sure they aren't interfering. It might seem over complicated, but I'm building it for extendability.

This works in a fla file:

var XMLAndFileLocation:String;
var quizXML:XML;
//var mainQuiz:Quiz;

function QuizBuilder(qXMLAndFileLocation:String)
{
XMLAndFileLocation=qXMLAndFileLocation;
//mainQuiz= new Quiz();
quizXML = new XML();
XMLLoader();
}

function XMLLoader()
{
quizXML.ignoreWhite = true;
quizXML.load(XMLAndFileLocation);

quizXML.onLoad = function(success) {
if(success){
trace(quizXML);
createQuiz(quizXML.firstChild);
}
}
}

function createQuiz(rootXML:XMLNode)
{
createSubQuiz(rootXML.firstChild);
}

function createSubQuiz(subQuizXMLNode:XMLNode)
{
trace(subQuizXMLNode);
switch (subQuizXMLNode.attributes.type)
{
case 'Multiple Choice': trace('Hallo');//mainQuiz.addSubQuiz(new MultipleChoiceQuiz());
break;
}
}

QuizBuilder('quiz.xml');
But when I put it in a class like this the traces return 'undefined'. Here is my class:

class QuizBuilder
{
private var XMLAndFileLocation:String;
private var quizXML:XML;
//private var mainQuiz:Quiz;

public function QuizBuilder(qXMLAndFileLocation:String)
{
XMLAndFileLocation=qXMLAndFileLocation;
//mainQuiz= new Quiz();
quizXML = new XML();
XMLLoader();
}

private function XMLLoader()
{
quizXML.ignoreWhite = true;
quizXML.load(XMLAndFileLocation);

quizXML.onLoad = function(success) {
if(success){
trace(quizXML);
createQuiz(quizXML.firstChild);
}
}
}

private function createQuiz(rootXML:XMLNode)
{
createSubQuiz(rootXML.firstChild);
}

private function createSubQuiz(subQuizXMLNode:XMLNode)
{
switch (subQuizXMLNode.attributes.type)
{
case 'Multiple Choice': trace('Hallo');//mainQuiz.addSubQuiz(new MultipleChoiceQuiz());
break;
}
}
}
I'd appreciate any advice anyone can give me. Thanks