I have a singleton class that loads in an XML file containing initial states for the files that are loaded in my application. When the user selects a module from a menu, this class is instantiated with the appropriate XML file. The problem I’m having is that after the user has run one of the modules, when they select another module, the states aren’t reloaded from scratch. Can someone please tell me what I’m doing wrong in the code below?
In the class itself:
// ActionScript Document
//IMI State Management Object
class images.classes.stateManager {
static var instance:stateManager;
var CURRENTLOADED:String = "NO";
var GLOBALLOADED:String = "NO";
var DOCSPARSED:Number = 0;
var currentInit:String = "";
var stateArray:Array = new Array();
var Initializer:Array = new Array();
var stateReady:Boolean = false;
var inited:Boolean = false;
//variables for overRiding XML values
var overRide:String = "0";
var overRideLOADED:String = "0";
public function getStateReady():Boolean {
return this.stateReady;
}
public static function getInstance(xmlFile:String):stateManager {
if (instance == null) {
instance = new stateManager(xmlFile);
}
return instance;
}
private function stateManager(fName:String) {
this.currentInit = fName;
this.initStateManager();
}
public function deleteInstance() {
instance = null;
CURRENTLOADED = "NO";
GLOBALLOADED = "NO";
DOCSPARSED = 0;
currentInit = "";
CURRINIT = "";
IDs = 0;
initCheck;
initCheck2;
initCheck3;
currentLRU = null;
InitScript;
InitScript2;
stateArray = new Array();
Initializer = new Array();
stateReady = false;
inited = false;
//variables for overRiding XML values
overRide = "0";
overRideLOADED = "0";
}
function initStateManager() {
if (inited != true) {
var rootApp = this;
this.InitScript = new XML();
this.InitScript.ignoreWhite = true;
this.InitScript.onLoad = function(success:Boolean) {
if (success) {
rootApp.ParseXML(this.firstChild);
}
};
this.InitScript.load(this.currentInit);
initCheck = setInterval(this, "loadGLOBAL", 50);
initCheck2 = setInterval(this, "resetInit", 50);
}
}
function loadGLOBAL() {
if (this.CURRENTLOADED == "YES") {
this.CURRINIT = this.currentInit;
this.currentInit = "./InitFiles/global.xml";
this.DOCSPARSED ++;
var rootApp = this;
var INIT = this.currentInit;
this.InitScript.onLoad = function(success:Boolean) {
if (success) {
rootApp.ParseXML(this.firstChild);
}
};
this.InitScript.load(this.currentInit);
clearInterval(initCheck);
}
}
function resetInit() {
if (this.GLOBALLOADED == "YES") {
this.currentInit = this.CURRINIT;
this.stateReady = true;
_root.monitor.text += "state is ready"+newline;
//this.reportStateNew();
this.GLOBALLOADED = "NO";
clearInterval(initCheck2);
}
if (this.overRideLOADED == "1") {
currentInit = this.CURRINIT;
this.stateReady = true;
_root.monitor.text += "state is now ready"+newline;
overRideLOADED = "0";
clearInterval(initCheck3);
}
}
function ParseXML(nextNode) {
while (nextNode<>null) {
var lastNode:XMLNode = nextNode;
nextNode = ParseCase(nextNode);
if (nextNode == null) {
if (lastNode.parentNode.nextSibling<>null) {
nextNode = lastNode.parentNode.nextSibling;
}
}
}
if (this.overRide != "1") {
if (this.DOCSPARSED == 1) {
this.GLOBALLOADED = "YES";
this.DOCSPARSED++;
} else {
this.DOCSPARSED++;
this.CURRENTLOADED = "YES";
}
} else {
this.overRide = "0";
this.overRideLOADED = "1";
}
if (this.GLOBALLOADED == "NO" && this.currentInit.indexOf("Global") != -1) {
this.GLOBALLOADED = "YES";
}
}
}
In my main file:
dropDown.onChange = function() {
_global.stateManager.deleteInstance();
_global.stateManager = null;
//Copied from NAV button!
_global.currentUnit = "";
currItem = ModuleArr[Number(eventObj.target.value)];
newMenu_mc.moduleName_txt.text = currItem.split(",")[0];
currModule = currItem.split(",")[1];
gotoAndStop(2);
_root.currentInit = currModule;
_global.currentInit = "./InitFiles/"+currModule+".xml";
_global.stateManager = stateManager.getInstance(_global.currentInit);
_global.stateManager.newXML(_global.currentInit);
}