topical media & game development

talk show tell print

#graphic-flex-image-effects-03-Flex-AbstractImageLoader.ax

#graphic-flex-image-effects-03-Flex-AbstractImageLoader.ax [swf] [flash] flex


  package {
  
          import flash.display.Bitmap;
          import flash.display.Loader;
          import flash.display.LoaderInfo;
          import flash.display.Sprite;
          import flash.events.Event;
          import flash.net.URLRequest;
  
          
Abstract base class to be used to load an image to process.

  
          public class @ax-graphic-flex-image-effects-03-Flex-AbstractImageLoader extends Sprite {
  
                  protected var _loadedBitmap:Bitmap;
  
                  
Constructor. Initiates load of image.
parameter: path The path to the image to load.

  
                  public function @ax-graphic-flex-image-effects-03-Flex-AbstractImageLoader(path:String) {
                          loadImage(path);
                  }
  
                  
Loads of image.
parameter: imagePath The path to the image to load.

  
                  private function loadImage(imagePath:String):void {
                          var loader:Loader = new Loader();
                          // just checks for success; a more robust class should also check for failures
                          loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
                          loader.load(new URLRequest(imagePath));
                  }
  
                  
Handler for when image loads successfully.
parameter: event Event dispatched by LoaderInfo.

  
                  private function onImageLoaded(event:Event):void {
                          var loaderInfo:LoaderInfo = event.target as LoaderInfo;
                          _loadedBitmap = loaderInfo.content as Bitmap;
                          runPostImageLoad();
                  }
  
                  
Abstract method that is called when image completes load and is ready to be processed. This should be overridden by child classes.

  
                  protected function runPostImageLoad():void {}
  
          }
  
  }


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.