Load XML files with loadXML()
Like opening webpages, loading an XML file in ActionScript 3.0 can require a lot more code than one might expect. One must create a URLLoader, a URLRequest, and add multiple event listeners. The global loadXML() function has been added to SimpleAS3 to quickly load an XML file with one function call.
Method Signature
function loadXML( url:String, onCompleteHandler:Function = null, onErrorHandler:Function = null ):void
Parameters
- url : String
The location of the XML file to load. May be an absolute or relative URL.
- onCompleteMethod : Function
The method to call when the asset finishes loading. Receives an
XMLobject.Note: There is a second parameter passed to this function, the
Eventobject received for the "complete" event, but it may be ignored if you don't need it. - onErrorMethod : Function
The method to call when an error causes the asset to fail loading. Receives an
ErrorEventobject. More specifically, it may be anIOErrorEventor aSecurityErrorEvent.
Usage Example
loadXML( "data.xml", dataCompleteHandler );
function dataCompleteHandler( xmlData:XML )
{
trace( xmlData.exampleElement.@exampleAttribute );
}