Actionscript 2.0 objects and arrays question

I’m attempting to create a small game to practice some new things I would like to learn. Right now, I’m attempting to load an XML file into Flash which creates an Item object and saves the object in with an array of objects. Loading the XML works fine, but for some reason, trying to push the new Items onto the array isn’t working. I’ve tested several things, and as far as I can tell it just doesn’t put anything in the array. I’m sure I’m overlooking something, but help would be appreciated. Here are the two classes I wrote to do this, as well as the code i’m using to test them. Thanks in advance for any help. :slight_smile:


//GameInventory class - load XML file and is supposed to store the information in an array of Item objects
class GameInventory {
	public var gameItems:Array;
	private var i:Number;
	public function GameInventory() {
		var setName:String
		var setHD:Number;
		var setGD:Number;
		var setID:Number;
		var setHO:Number;
		var setGO:Number;
		var setIO:Number;
		
		var itemslist_xml:XML = new XML();	
		itemslist_xml.ignoreWhite = true;		
		itemslist_xml.onLoad = function(success:Boolean) {
			if (success) {
				for (i=0;i<itemslist_xml.childNodes.length;i++) {
					setName = itemslist_xml.childNodes*.childNodes[0].firstChild.nodeValue;
					setHD = Number(itemslist_xml.childNodes*.childNodes[1].firstChild.nodeValue);
					setGD = Number(itemslist_xml.childNodes*.childNodes[2].firstChild.nodeValue);
					setID = Number(itemslist_xml.childNodes*.childNodes[3].firstChild.nodeValue);
					setHO = Number(itemslist_xml.childNodes*.childNodes[4].firstChild.nodeValue);
					setGO = Number(itemslist_xml.childNodes*.childNodes[5].firstChild.nodeValue);
					setIO = Number(itemslist_xml.childNodes*.childNodes[6].firstChild.nodeValue);
					gameItems.push(new Item(setName,setHD,setGD,setID,setHO,setGO,setIO));
				}
			} else {
				trace("Unable to load items list");
			}
		}		
		itemslist_xml.load("xml/itemslist.xml");
	}		
	public function findItem(itemName:String):Item {  //Does not work at all yet for some reason
		for (i=0;i<gameItems.length;i++) {
			if (itemName == gameItems*.itemName) {
				return gameItems*;
			}
		}
	}
}
//Item class - creates an object with the information it recieves from the GameInventory class when the XML file is loaded.
class Item {
	private var itemName:String;
	private var healthDefense:Number;
	private var geekDefense:Number;
	private var intellectDefense:Number;
	private var healthOffense:Number;
	private var geekOffense:Number;
	private var intellectOffense:Number;	
	
	public function Item(getName,getHD,getGD,getID,getHO,getGO,getIO) {
		itemName=getName;
		healthDefense=getHD;
		geekDefense=getGD;
		intellectDefense=getID;
		healthOffense=getHO;
		geekOffense=getGO;
		intellectOffense=getIO;
	}
	public function getItemName() {
		return itemName;
	}
}
//the test code that's one the first frame of the Flash movie
var listInventory:GameInventory = new GameInventory();
var item1:Item = new Item();
item1 = listInventory.findItem("Dictionary");
trace(item1.getItemName());  //displays "Undefined" instead of "Dictionary", like its supposed to.