title: Does ActionScript 3 require an error event handler for XML?
body: <p>In a Flash game I am developing, there are some settings that are set by an external XML file.  When I run the SWF file through the Flash IDE, it loads fine.  If I run the same file as a projector (.exe) or the independent SWF file, it does not load the XML file.</p>
  
  <p>My (unexpected) fix was to assign an <em>error</em> event listener to the loader object.  When I published the file again, the XML loaded properly in the projector and standalone SWF files.  (I have since verified that commenting out the error event handler restores the bug).</p>
  
  <p>Here's the block of code involved (<del>with extraneous code and function calls removed</del>):</p>
  
  <pre><code>public function getSettings():void {
  outputBox = getChildByName("output_box") as TextField;
  var xmlLoader:URLLoader = new URLLoader();
  var xmlData:XML = new XML();                
  xmlLoader.addEventListener(Event.COMPLETE, loadXML, false, 0, true); 
  xmlLoader.addEventListener(ErrorEvent.ERROR, function (e:Error) 
      { outputBox.appendText(e.message) });
  
  try {               
      xmlLoader.load(xmlPath);
  } 
  catch(err:Error) {
      trace(err.message);
      outputBox.appendText(err.message);
      checkChances("0");
  }
  
  function loadXML(e:Event):void {
  
      try {
          xmlData = new XML(e.target.data);
          var chances:String = xmlData.chances.text();
          var dbURL:String = xmlData.database.text();
  
          trace("Chances are set to: " + chances);                    
          trace("Database URL is set to: " + dbURL);
          outputBox.appendText("Chances are set to: " + chances);
      }
      catch(err:Error) {              
          outputBox.appendText(err.message);
      }
          checkChances(chances);
          dbPath = new URLRequest(dbURL);
  }           
  </code></pre>
  
  <p>}</p>
  
  <p>Let me know if you have run into this, or if you can shed some light on what may be happening.  Thanks!</p>
  
  <p>EDIT:</p>
  
  <p>Here is the code which does <em>not</em> work. (I also edited the code that does work to show all the other bits that I took out, just in case they might be effecting it):</p>
  
  <pre><code>public function getSettings():void {
  outputBox = getChildByName("output_box") as TextField;
  var xmlLoader:URLLoader = new URLLoader();
  var xmlData:XML = new XML();                
  xmlLoader.addEventListener(Event.COMPLETE, loadXML, false, 0, true); 
  /*xmlLoader.addEventListener(ErrorEvent.ERROR, function (e:Error) 
      { outputBox.appendText(e.message) });*/
  
  try {               
      xmlLoader.load(xmlPath);
  } 
  catch(err:Error) {
      trace(err.message);
      outputBox.appendText(err.message);
      checkChances("0");
  }
  
  function loadXML(e:Event):void {
  
      try {
          xmlData = new XML(e.target.data);
          var chances:String = xmlData.chances.text();
          var dbURL:String = xmlData.database.text();
  
          trace("Chances are set to: " + chances);                    
          trace("Database URL is set to: " + dbURL);
          outputBox.appendText("Chances are set to: " + chances);
      }
      catch(err:Error) {              
          outputBox.appendText(err.message);
      }
          checkChances(chances);
          dbPath = new URLRequest(dbURL);
  }           
  </code></pre>
  
  <p>}</p>