this is a xml loader class for use with as2.
import mx.utils.Delegate; import mx.display.*; import mx.events.*; import mx.utils.*; class mwm.data.xmlData extends EventDispatcher { private static var XML_AR_ARRAY:Array; private static var XML_DATA_TRUE:Boolean; private static var XML_DATA_ARRAY:Array; public var xmlArray:Array; private var xm; public var dispatchEvent:Function; public var addEventListener:Function; public var removeEventListener:Function; function xmlData() { EventDispatcher.initialize(this); } function load(file) { XML_DATA_ARRAY = new Array(); var thisObj:xmlData = this; xm = new XML(); XML_DATA_ARRAY = new Array(); xm.ignoreWhite = true; xm.onLoad = Delegate.create(this, runEvent); xm.load(file); } function runEvent(loaded:Boolean) { var full_arr = xm.firstChild.childNodes; var len:Number = full_arr.length-1; for(var i:Number=0;i<=len;i++){ XML_AR_ARRAY = new Array(); for(var a:Number=0;a<=full_arr[i].childNodes.length-1;a++){ var st = full_arr[i].childNodes[a].firstChild.nodeValue; XML_AR_ARRAY.push(st); } XML_DATA_ARRAY.push(XML_AR_ARRAY); } if(loaded){ xmlArray = XML_DATA_ARRAY; dispatchEvent({type:"onLoad",target:this}); } } }
to use this class, u must change the mwm.data on the class name line to the path that it is it from the flash file keeping xmlData on the end.
then import it into the flash doc,
and the actionscript to use is
for example
var something:xmlData = new xmlData(); var somethingObj = new Object(); something.addEventListener('onLoad',somethingObj); somethingObj.onLoad = function() { once xml loaded, do my stuff in here trace(something.xmlArray); } something.load('myxml.xml');
hope it helps with lengthy process of xml loading, this also supports multiple xml sheets per flash movie