Tuesday 19 January 2010

XML loading class

This article is about loading xml data, on files or webservices. Sometimes, some projects require that you must read lots of information that are scattered throught many xml files or webservice. This class will help you not to recode every time you must read such type of information. Instead you only have to read the data acording to the response you receive.

So if you use this class, you just need to instatiate an object and call the file/webservice. Instantiate a new object for each file/webservice.

This code was copied from the website: http://www.mediareason.com/blog/?p=20

package com.func
{
import flash.net.URLLoader
import flash.net.URLRequest
import flash.xml.XMLDocument;
import flash.errors.*
import flash.events.*
public class LoadXML
{
private var loader : URLLoader;
private var mainXML : XML;
public function LoadXML() {
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("http://.../test.xml"));
}
private function onComplete(evt:Event)
{
try
{
mainXML = new XML(loader.data)
trace(mainXML);
} catch(e:Error)
{
trace("Error: " + e.message)
return;
}
}
}
}