1 Reply Latest reply on Aug 3, 2007 3:36 PM by ogden_shooter

    Image Load Failure

      I have a program that dynamically loads images from a database, loads them mirrors them, then adds them to the rawChildren of the Canvas, however, if an image does not exist is there a way to test the image existence and if that fails load a 'dummy' image? I have the following code:

      public function imgLoader():void
      var context:LoaderContext = new LoaderContext();
      context.checkPolicyFile = true;
      this.img = new Image();
      this.img.source = this.img_path;
      this.img.maintainAspectRatio = true;
      this.img.scaleContent = false;
      this.img.autoLoad = false;
      this.img.loaderContext = context;
      this.img.addEventListener(Event.COMPLETE, handleImageLoad);
      try {
      } catch(err:*) {
      Alert.show("Cannot load Image: " + this.img_path);

      then of course i have a event listener function that does all the fun img stuff once the image loads.

      However, if the image does not exist, then the Event.COMPLETE is never called, the try is "successful" as far as Flex is concerned, is there an event listener that I'm missing that fires if the load fails?

        • 1. Re: Image Load Failure
          ogden_shooter Level 1
          As it turns out this was easier than expected....
          I added the following listener:
          this.img.addEventListener(IOErrorEvent.IO_ERROR, handleImageError);

          function handleImageError(e:IOErrorEvent):void {
          Alert.show("cannot load image: " + img_path);

          and there it was the Alert that i was expecting when my image path fails!