I'm trying to a make a simple class in an actionscript file that handles the reading in and parsing/managing of an xml file. This class takes a movieclip as a parameter and has the movie clip act according to the results of the import. I've tried this:
class FileReader {
var menu:MovieClip;
function FileReader(newMenu) {
menu = newMenu;
}
//Load the specified xml file
function loadFile(fileName) {
menu.gotoAndStop("loading");
var name = levelName+".xml";
var xmlFile = new XML();
xmlFile.ignoreWhite = true;
xmlFile.load(name);
xmlFile.onLoad = function() {
//Parse Input
menu.gotoAndStop("loaded");
};
}
}
For some reason, when the code reaches the onLoad function, the file loads properly but the application has no more knowledge of the existence of the menu movieclip. If I try to trace any attributes of the menu, it says it is undefined. So then I tried this:
class FileReader {
var menu:MovieClip;
var xmlFile:XML;
function FileReader(newMenu) {
menu = newMenu;
}
//Load the specified xml file
function loadFile(fileName) {
menu.gotoAndStop("loading");
var name = fileName+".xml";
xmlFile = new XML();
xmlFile.ignoreWhite = true;
xmlFile.load(name);
xmlFile.onLoad = function() {
//Parse Input
menu.gotoAndStop("loaded");
};
}
}
In this case, the xml file won't load at all, and the xmlFile object is undefined. What's going on here and why are neither of these approaches working?