How to embed XML file in Flex and Actionscript 3

On September 13, 2013, in Flash Flex AIR, by James Liu

There are lots of articles to demonstrate how to embed the XML file in Flex and Actionscript 3. But it takes me almost 30 minutes to try and none of them works for me. Finally, I write my own test code and find the right way to embed the XML file in Flex with Actionscript 3, and access the data with XML object. I hope it will help you and save your time.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" layout="absolute" minWidth="955" minHeight="600" creationComplete="onCreationComplete(event)">
			protected var EmbeddedXML:Class;	
			private function onCreationComplete(event:Event):void
				//doesn't work
				//var a:XML = EmbeddedXML as XML;
				//trace("a: " + a.toXMLString());
				var b:XML = new XML(;
				trace("b: " + b.toXMLString());
				//doesn't work
				var c:XML = XML(new EmbedXML());
				trace("c: " + c.toXMLString());
				//doesn't work
				var d:XML = new XML(new EmbedXML());
				trace("d: " + d.toXMLString());
				var e:XML = as XML;
				trace("e: " + e.toXMLString());
				//doesn't work
				//var f:XML = new EmbeddedXML() as XML;
				//trace("f: " + f.toXMLString());
Tagged with:  

Leave a Reply

Free WordPress Theme