Flash AS3 - Display an error if the XML if incorrect

Posted by ongoingworlds on Stack Overflow See other posts from Stack Overflow or by ongoingworlds
Published on 2010-06-09T12:16:21Z Indexed on 2010/06/09 21:22 UTC
Read the original article Hit count: 337

Filed under:
|
|

Hi, I'm creating a flash application which loads in some XML which is generated dynamically from the CMS. I want to display an error in case the XML file isn't formatted correctly. When I test this with incorrectly formatted XML, it will just get to the line myXML = XML(myLoader.data); and then just bomb out. How can I catch the error, display a message to the user, but the flash program to continue as normal.

var myXMLURL:URLRequest = new URLRequest(XMLfile); 
var myLoader:URLLoader = new URLLoader(myXMLURL); 
myLoader.addEventListener(Event.COMPLETE, xmlLoaded); 
myLoader.addEventListener(IOErrorEvent.IO_ERROR, xmlFailed);
var myXML:XML;

//--when the xml is loaded, do this
function xmlLoaded(e:Event):void 
{ 
    myXML = XML(myLoader.data);
    trace("XML = "+myXML);
}

//--if the xml fails to load, do this
function xmlFailed(event:IOErrorEvent):void
{
    errorMsg.text = "The XML file cannot be found"  
}

© Stack Overflow or respective owner

Related posts about Xml

Related posts about flash