Saturday, May 19, 2007

Loading XML into Flash

This is not something new, i think everyone already knows this..but for me, ive been using other people codes and not my own. So anyways im working on this flash that uses FMS and i dont want to encode the rtmp server hardcoded in the flash, so i thought i should have the settings in an XML file much like a .net application, guess what.. i dont know how to do it.. i have a number of scripts that will load all the child to a tree or a list.. but not a simple one, so with a few internet search found a few good tutorials, well here is My Quick and Dirty guide to it.

1) Create the XML file (mine uses just the child attributes) - (save it as settings.xml) so here it is...
<settings>
<setting rtmpserver="rtmp:/app1" playserver="http://visual/play" />
</settings>


2) in Flash Quite simply this is the code
var myXml:XML = new XML();
myXml.ignoreWhite = true;
myXml.load("settings.xml");

myXml.onLoad = function(success) {
if (success) {
rtmpSvr = this.firstChild.childNodes[0].attributes.rtmpserver
playSvr = this.firstChild.childNodes[0].attributes.playserver
trace(rtmpSvr + " - " + playSvr)
}
}



and thats it...

No comments: