1 Reply Latest reply on May 19, 2009 5:59 PM by Moenizzle

    Progress bar lags when image is being loaded


      I am trying to load a series of images and display them in a TileList as thumbnails.  The problem is that, depending on how many images are loaded at once, there is a long delay.  I'm okay with the delay as long as I can display some sort of indeterminate progress bar.  Unfortunately, the application sort of hangs as the images are loading and the progress bar freezes/lags.  I'm wondering if there is a way to remedy this.


      Here are the steps I go through to load an image:

      1. Load an image into a ByteArray using fileReference.load()

      2. Load those bytes into a Loader using loader.loadBytes(..)

      3. Retrieve the content Bitmap from the Loader and scale it using bitmapData.copyPixels(..)


      Below is some code that is basically in sequence:


























      // Load the image from a file



      public function load():Boolean




           if(_fileReference != null)


                _fileReference.addEventListener(Event.COMPLETE, onFileLoadComplete);




                return true;





           return false;






      // Fired after the FILE is loaded



      public function onFileLoadComplete(event:Event):void




           var currFileReference:FileReference = FileReference(event.target);

           currFileReference.removeEventListener(Event.COMPLETE, onFileLoadComplete);







      // Begins loading the IMAGE into memory



      public function loadImage(imageByteArray:ByteArray):void




           var loader:Loader = new Loader();

           loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoadComplete);







      // Fired after the IMAGE is loaded



      public function onImageLoadComplete(event:Event):void




           var loaderInfo:LoaderInfo = LoaderInfo(event.target);

           loaderInfo.removeEventListener(Event.COMPLETE, onImageLoadComplete);





           // Set ORIGINAL size image





           this.originalImage = loaderInfo.loader.content as Bitmap;



           this.originalImage.smoothing = true;






           // Set SCALED size image





           var minDimension:Number = this.originalImage.width > this.originalImage.height ? this.originalImage.height : this.originalImage.width;



           var x:Number = Math.max(0, (this.originalImage.width / 2) - (minDimension / 2));



           var y:Number = Math.max(0, (this.originalImage.height / 2) - (minDimension / 2));



           this.scaledImage = cropBitmap(this.originalImage, x, y, minDimension, minDimension);



           this.scaledImage.smoothing = true;
















           var croppedBitmapData:BitmapData = new BitmapData(w, h);


      function cropBitmap(sourceBitmap:Bitmap, x:Number, y:Number, w:Number, h:Number):Bitmap



      new Rectangle(x, y, w, h), new Point(0, 0));



           return new Bitmap(croppedBitmapData);



      Any help would be GREATLY appreciated!