It is very easy to load and parse XML in Action Script 3.0
Suppose we have xml like this -
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <images>
<image>
<url>"first.jpg"</url>
</image>
<image>
<url>"Second.jpg"</url>
</image>
<image>
<url>"Third.jpg"</url>
</image><images>
So for load and parse we have few lines code below :
public function loadXML():void
{
//path of xml file
var url:String = "...//images.xml"
var imagesLoader:URLLoader = new URLLoader()
try
{
var imagesURL:URLRequest=new URLRequest(url)
imagesLoader.load(imagesURL)
imagesLoader.addEventListener(Event.COMPLETE,loadImages)
imagesLoader.addEventListener(IOErrorEvent.IOERROR,ioError)
}
catch(e)
{
}
}
public function ioError(evt:IOErrorEvent):void
{
trace("ERROR")
}
private function loadImages(evt:Event):void
{
var itemsXML:XML= new XML(evt.target.data)
for each (var image:XML in xmlData.image)
{
trace("get images url ",image.url)
}
}
May be it would help !
0 Comment(s)