[thelist] Flash & XML

Spencer, Graham Graham.Spencer at NielsenMedia.com
Fri Jul 16 11:33:06 CDT 2004


-----Original Message-----
From: Richard Osborne

I've been banging my head against a brick wall with Flash & XML for too long
now. Does anybody know of a good tutorial for making sense of an XML file in
Flash? Getting it in is no problem - actually using the data is a bit more
tricky ...

Rich Osborne

-- 
Pretty simple really, two things to make sure of first.
1) use an onload function to make sure the XML is loaded, I usually make a
call to a function to parse my XML with an onload function:

var xmlVal:XML = new XML();
xmlVal.ignoreWhite = true;
xmlVal.onLoad = function(mySuccess:Boolean):Void {
	if (mySuccess) {
		//perform my function, etc.
	} else {
		trace("There was an Error in loading the XML document");
	}
}

2) make sure you include the ingnore whitespace.
After that call a function and build an array, by parsing the XML.

assuming an xml structure like this:
<myXML>
	<childOne>
		<item1>1</item1>
		<item2>2</item2>
		<item3>3</item3>
	</childOne>
</myXML>


function xmlTree():Array {
	var xnRoot:XMLNode = xmlVal.firstChild;
	//Child one
	var xnChildOne:Array = xnRoot.childNodes;
	var xnChildern:Array = new Array();
	//build array of Child One's childern
	for (var i = 0; i<xnChildOne.length; i++) {
		xnChildern[i] = xnChildOne[i];
	}
}

Make any sense?

Graham Spencer


More information about the thelist mailing list