Resetting a class

I’ve created a singleton class to load in that initial states for certain modules. This class loads in 2 XML files, first a global.xml, which contains a pre-set set of states for the entire project, is loaded into one array. It then loads in the appropriate xml file for the module that was chosen into another array. I then have the class copy the first array into an array called stateArray then overwrites items in the stateArray with the values in the 2nd array.
I’ve also added a function to reset the class when the user selects a new module.
This class works fine the first time I select a module the first time. However, when I go to select a second module, my code doesn’t seem to be calling the reset function properly. Could someone please look at my code below and tell me what I’m doing wrong?

[AS]
class images.classes.stateManager {
static var instance:stateManager;
var initCheck:Number;
var initCheck2:Number;
var stateReady:Boolean = false;
var currentInit:String = “”;
var currentLRU:String = “”;
var tempInit:String = “”;
var globalArray:Array = new Array();
var indivArray:Array = new Array();
var stateArray:Array = new Array();
var indivDone:Boolean = false;
var globalDone:Boolean = false;

var initScript:XML;
public function getStateReady() {
return this.stateReady;
}
public static function getInstance(xml:String):stateManager {
if (instance == null) {
instance = new stateManager(xml);
}
return instance;
}
private function stateManager(xmlFile:String) {
this.currentInit = xmlFile;
this.initStateManager();
}
public function resetInstance() {
this.stateArray = null;
instance = null;
this.indivArray = new Array();
this.currentInit = “”;
this.stateReady = false;
}
public function initStateManager() {
var rootApp = this;
this.stateArray = new Array();
this.tempInit = this.currentInit;
this.currentInit = “./InitFiles/global.xml”;
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, “loadIndivXML”, 50);
initCheck2 = setInterval(this, “copyArrays”, 50);
}
private function loadIndivXML() {
if (this.globalDone) {
this.currentInit = this.tempInit;
var rootApp = this;
this.initScript = new XML();
this.initScript.ignoreWhite = true;
this.initScript.onLoad = function (succ:Boolean) {
if (succ) {
rootApp.parseXml(this.firstChild);
}
}
this.initScript.load(this.currentInit);
clearInterval(initCheck);
}
}
private function copyArrays() {
if (this.globalDone && this.indivDone) {
this.stateArray = this.globalArray;
this.stateReady = true;
for (var elmt in this.indivArray) {
for (var id in this.indivArray[elmt].idStates) {
stateArray[elmt].idStates[id] = indivArray[elmt].idStates[id];
}
}
clearInterval(initCheck2);
}
}
private function parseXml(nextNode) {
while (nextNode != null) {
var lastNode = nextNode;
nextNode = parseCase(nextNode);
if (nextNode == null) {
if (lastNode.parentNode.nextSibling != null) {
nextNode = lastNode.parentNode.nextSibling;
}
}
}
//If we’ve just finished global.xml, set that variable,
//otherwise, set indivDone.
if (this.currentInit.indexOf(“global”) != -1) {
this.globalDone = true;
this.currentInit = this.tempInit;
} else {
this.indivDone = true;
}
}
function parseCase(currNode) {
var nextNode:XMLNode;
var arr:Array;
if (this.currentInit.toLowerCase().indexOf(“global”)!=-1) {
arr = this.globalArray;
} else {
arr = this.indivArray;
}
switch (currNode.nodeName) {
case “IMI”:
nextNode = currNode.firstChild;
break;
case “lru”:
this.currentLRU = currNode.attributes.name;
if (arr[currentLRU]==undefined) {
arr[currentLRU]=new Array();
}
arr[currentLRU].lruStatus = Number(currNode.attributes.status);
if (arr[currentLRU].idStates==undefined) {
arr[currentLRU].idStates = new Array();
}
nextNode = currNode.firstChild;
break;
case “id”:
if (arr[currentLRU].idStates[this.currentLRU]==undefined) {
var stateArr = currNode.firstChild.nodeValue;
arr[this.currentLRU].idStates[currNode.attributes.name] = stateArr;
}
nextNode = currNode.nextSibling;
break;
default:
break;
}
return nextNode;
}
public function setStateCurrent(lru, id, newVal) {
var newId = id.split("_mc").join("");
stateArray[lru].idStates[newId]=newVal;
}
public function getStateCurrent(lru, id) {
var newId = id.split("_mc").join("");
return stateArray[lru].idStates[newId];
}
public function getLRUCurrent(lru):Object {
var returnArray:Object = new Object();
for (var element in this.stateArray[lru].idStates) {
returnArray[element] = this.stateArray[lru].idStates[element];
}
return returnArray;
}
}
[/AS]
And here is the code within the main program:
[AS]
ModuleDrop.onChange = function() {
_global.stateManager.resetInstance();
_global.stateManager = null;
//Copied from NAV button!
_global.currentUnit = “”;
currItem = ModuleArr[Number(eventObj.target.value)];
currModule = currItem.split(",")[1];
_root.currentInit = currModule;
_global.currentInit = “./InitFiles/”+currModule+".xml";
_global.stateManager = stateManager.getInstance(_global.currentInit);
}
[/AS]

I really appreciate all the help I can get.