title: Flash AS3 - Display an error if the XML if incorrect
body: <p>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. </p>
  
  <pre><code>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"  
  }
  </code></pre>