2 Replies Latest reply on Jun 29, 2006 8:25 AM by Jan-Paul K.

    Throwing an Exception for  a xml file that can't be found.

    jelaplan
      I'd like to catch a file load error and provide feedback to the user. I'm building a educational excercise and if the problem doesn't load, I'd like to politely let the student know. I've written a try-catch block which catches a file load exception fine in the Flash IDE and in Internet Explorer but doesn't catch it in Firefox. The onLoad method doesn't appear to get called when the file isn't found, i.e., success == false.

        • 1. Re: Throwing an Exception for  a xml file that can't be found.
          Jan-Paul K. Level 1
          the most simple way would be this:
          var my_xml:XML = new XML();
          my_xml.onLoad = function(success:Boolean){
          if(success){
          trace("load success");
          } else {
          trace("failed loading");
          }
          };
          my_xml.load("my.xml");

          May I ask why you are trying to throw an error and catch it in the same method, does this make sense?

          Maybe you should try something like this:

          class Xmlloader {
          function Xmlloader(xmlFilePath:String) {
          loadQuestionFile(xmlFilePath);
          }
          public function loadQuestionFile(theBRDFileName:String):Void {
          var myXML = new XML();
          myXML.ignoreWhite = true;
          myXML.callbackReference = this;
          myXML.onLoad = function(success:Boolean) {
          trace("onLoad event caught");
          this.callbackReference.handleLoad(success);
          };
          myXML.load(theBRDFileName);
          }

          public function handleLoad(success:Boolean) {
          if (success) {
          trace("XML Loaded :-)");
          this.onLoadSuccess();
          } else {
          trace("XML not Loaded :-(");
          this.onLoadFailure();
          }
          }

          public function onLoadFailure(){};
          public function onLoadSuccess(){};
          }

          now the onLoadFailure function gets called if the xml file could not be loaded, and the onLoadSuccess function if everything went fine.
          • 2. Throwing an Exception for  a xml file that can't be found.
            Jan-Paul K. Level 1
            maybe this makes more sense (bit shorter)