Need Help with xml in flash

ucohockey
ucohockey used Ask the Experts™
on
I have a file that I'm having problems displaying the xml. I only get undefined. I have pasted the code below can someone please tell me how to access each var. I have the file displaying the current amount of items I just cant display the data. When I trace the newsItems it shows everything but when I try to trace a specif var it comes up undefined. If you look at the code below you will see where I'm trying to trace the game_id, and it's undefined.
// XML Data
var newsDataMLB:XML = new XML();
newsDataMLB.ignoreWhite = true;
 
// On XML Load
newsDataMLB.onLoad = loadItemsMLB;
 
// load news data
newsDataMLB.load("http://www.pucksandmore.com/scores.xml");
 
//empty movieclip
 
// Loading items
function loadItemsMLB() {
 
	newsItemMLB = newsDataMLB.childNodes[0];
	menuItemsLength = newsItemMLB.childNodes.length;
	trace(newsItemMLB);
}
 
for (var i:Number = 0; i<nColumn; i++) {
 
		var nIndex:Number = nCurrentIndex+i;
 
		// Checking index postions & setting next & previous buttons
		mcPagination.nextBtn.enabled = true;
		mcPagination.nextBtn.gotoAndStop("fn_enabled");
 
		mcPagination.prevBtn.enabled = true;
		mcPagination.prevBtn.gotoAndStop("fn_enabled");
 
 
		var nIndexPlus:Number = nIndex+1;
 
		if (nIndexPlus>=menuItemsLength) {
			mcPagination.nextBtn.enabled = false;
			mcPagination.nextBtn.gotoAndStop("fn_disabled");
		}
		
		if (nCurrentIndex<=1) {
			mcPagination.prevBtn.enabled = false;
			mcPagination.prevBtn.gotoAndStop("fn_disabled");
		}
		
		    if (menuItemsLength<1 and nCurrentIndex<1) {
			mcPagination.gotoAndStop("over");
		}
		
		if (nIndex>=menuItemsLength) {
			mcPagination.nextBtn.enabled = false;
			mcPagination.nextBtn.gotoAndStop("fn_disabled");
			break;
		}
		
		var GameId:String = items[nIndex].childNodes[0].attributes.game_id;
		var Sport:String = items[nIndex].childNodes[1].attributes.sport;
		var vTeamId:String = items[nIndex].childNodes[2].attributes.vteamid;
		var hTeamId:String = items[nIndex].childNodes[3].attributes.hteamid;
		var vTeam:String = items[nIndex].childNodes[4].attributes.vTeam;
		var hTeam:String = items[nIndex].childNodes[5].attributes.hTeam;
		var vName:String = items[nIndex].childNodes[6].attributes.vname;
		var hName:String = items[nIndex].childNodes[7].attributes.hname;
		var vScore:String = items[nIndex].childNodes[8].attributes.vscore;
		var hScore:String = items[nIndex].childNodes[9].attributes.hscore;
		var Status:String = items[nIndex].childNodes[10].attributes.status;
		var Status2:String = items[nIndex].childNodes[11].attributes.status2;
		var Preview:String = items[nIndex].childNodes[12].attributes.preview;
		var Log:String = items[nIndex].childNodes[13].attributes.log;
		var Wrap:String = items[nIndex].childNodes[14].attributes.wrap;
		var Box:String = items[nIndex].childNodes[15].attributes.box;
}
trace(GameId);

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Your entire for loop (and trace) have to be in the loadItemsMLB()  function. Imagine that your xml file is 20mb large. By the time flash has finaly loaded your xml file, it has already executed the rest of your script, including your for loop and trace.

Next you use an 'items' variable/array that's not declared anywhere? Also, your data isnt defined as attributes, so you have to use '.firstChild.nodeValue' in stead of '.attributes.xxx'

Author

Commented:
Thanks for the reply I had an emergency and I'm just now getting back on this. Sprry about the items it was from so code that I was taking out. But with that said would I use newsItemMLB instead. I also have tried using nodeValue but still have no success.

Thanks
Snippet 1 is a trace of your xml document.
Snippet 2 is an example to convert each game node to an object for easy access
//1
// XML Data
var newsDataMLB:XML = new XML();
newsDataMLB.ignoreWhite = true;
 
// On XML Load
newsDataMLB.onLoad = loadItemsMLB;
 
// load news data
newsDataMLB.load("http://www.pucksandmore.com/scores.xml");
 
//empty movieclip
 
// Loading items
function loadItemsMLB() 
{
	for(var i:Number = 0; i<newsDataMLB.firstChild.childNodes.length; i++)
	{
		trace("Game node:");
		var gameNode:XMLNode = newsDataMLB.firstChild.childNodes[i];
		for(var j:Number = 0; j<gameNode.childNodes.length; j++)
		{
			trace("\t" + gameNode.childNodes[j].nodeName + ": " + gameNode.childNodes[j].firstChild.nodeValue);
		}
	}
	
}
	
 
 
 
 
//2
// XML Data
var newsDataMLB:XML = new XML();
newsDataMLB.ignoreWhite = true;
 
// On XML Load
newsDataMLB.onLoad = loadItemsMLB;
 
// load news data
newsDataMLB.load("http://www.pucksandmore.com/scores.xml");
 
//empty movieclip
 
// Loading items
function loadItemsMLB() 
{
	for(var i:Number = 0; i<newsDataMLB.firstChild.childNodes.length; i++)
	{
		var gameNode:XMLNode = newsDataMLB.firstChild.childNodes[i];
		var ob:Object = new Object();
		for(var j:Number = 0; j<gameNode.childNodes.length; j++)
		{
			ob[gameNode.childNodes[j].nodeName] = gameNode.childNodes[j].firstChild.nodeValue;
		}
		
		trace(ob.vname);
		trace(ob.hname);
		trace(ob.vteam);
		trace(ob.hteam);
		trace("etc");
	}
	
}
	

Open in new window

Author

Commented:
TheDauntless,

Thanks for the reply. I'm going to accept your answer it was right. I'm in need of some more quick work are you interested. It needs to be done asap. If so I can send you my email and we can discuss price.

Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial