1 Reply Latest reply on May 27, 2008 1:57 PM by slaingod

    Loading several SWF files simultaneously sometimes fails

    stigbn Level 1

      I want to load 10 different SWF files in a simple for loop using the SWFLoader. This sometimes fails meaning that only 8 or 9 of the load operations actually completes (the missing ones are not failing - they just never fire the complete event) .

      Below is some simple test code that illustrates the problem. This test code counts the number of times various events are fired. If for instance only 8 of 10 load operations are completed, then there will have been fired 10 open events, but only 8 init, httpstatus and complete events (and no io error events), but you can try for your self with this code:

      // This code is loading a number of SWF files simultaneously (in a loop).
      // The problem is that momst of the time, not all files are loaded.
      // If an array of filepaths to 10 different files is used, then sometimes only 8 of the
      // files are loaded, sometimes only 9 and sometimes all 10. When some files are
      // not being loaded, then the init, httpstatus and complete event is not fired, the but the open
      // event is.
      // What is wrong, and what can be done to ensure that all files in the array is always loaded ?
      private var loaderCompleteCount:int;
      private var loaderIOerrorCount:int;
      private var loaderOpenCount:int;
      private var loaderInitCount:int;
      private var loaderHttpStatusCount:int;

      public function MakeLoadTest(filePaths:Array):void
      loaderCompleteCount = 0;
      loaderIOerrorCount = 0;
      loaderOpenCount = 0;
      loaderInitCount = 0;
      loaderHttpStatusCount = 0;
      for each(var path:String in filePaths)


      private function testLoadSWF(path:String, completeEventCallBack:Function):void
      var loader:SWFLoader = new SWFLoader;
      loader.addEventListener(Event.COMPLETE, function(event:Event):void {loaderCompleteCount++; completeEventCallBack()});
      loader.addEventListener(IOErrorEvent.IO_ERROR, function(even:Event):void {loaderIOerrorCount++;});
      loader.addEventListener(Event.OPEN, function(event:Event):void {loaderOpenCount++;});
      loader.addEventListener(Event.INIT, function(event:Event):void {loaderInitCount++;});
      loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, function(event:Event):void {loaderHttpStatusCount++;});

      private function GetResult():String
      var result:String = "\nloaderCompleteCount = "+loaderCompleteCount;
      result += "\nloaderIOerrorCount = "+loaderIOerrorCount;
      result += "\nloaderOpenCount = "+loaderOpenCount;
      result += "\nloaderInitCount = "+loaderInitCount;
      result += "\nloaderHttpStatusCount = "+loaderHttpStatusCount;
      return result;

      I think there is some timing issuses in this, so one idea I am considering is to make some sequencing, so that the next load operation is not started until the previous has completed.

      Any help with getting this code to always load all the files is much appreciated !!!

      best regards Stig