Load Images with A Loop

Hello, right now I am trying to load images continuously with a loop until there are no more. What I have done so far is load “image”+n+".jpg" until Flash can’t load anymore, in which case an IOError would be given. When the IOError is given, the loop should break, but right now the problem I am having is that the event listener I set up for the IOError is executing after the loop ends, which defeats the purpose of why I had it there. Here is the code I am using (the fla I have is just a blank one that uses this class for its document class):

 
package {
 import flash.events.*;
 import flash.display.*;
 import flash.net.*;
 import flash.errors.*;
 
 public class listings extends Sprite {
  public function listings() {
   loadImages();
  }
 
  var loader:Loader;
  var curImgNum:int = 1;
  var numImages:int = 0;
  var imageContainer:Sprite;
  public var breakFromLoop:Boolean = false;
 
  private function onIOError(event:IOErrorEvent):void {
   breakFromLoop = true;
   trace(breakFromLoop);
  }
 
  public function onComplete(event:Event):void {
   event.target.content.width /= 5;
   event.target.content.height /= 5;
  }
 
  private function loadImages():void {
   //the condition for the loop is just temporary, it should be an infinite one since the IOError will be the thing that breaks the loop
   while (numImages < 6) {
    trace(breakFromLoop);
    if (breakFromLoop == true) {
     trace("break");
     break;
    }
     loader = new Loader();
     imageContainer = new Sprite();
 
     loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
     loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
     loader.load(new URLRequest("image"+curImgNum+".jpg"));
 
     //temporary positioning code i am using
     imageContainer.x = Math.random() * 700 + 1; 
     imageContainer.y = Math.random() * 400 + 1;
     imageContainer.addChild(loader);
     addChild(imageContainer);
 
     curImgNum++;
     numImages++;
   }
  }
 }
}

Please advise. Any help is appreciated.