2 Replies Latest reply on May 31, 2006 9:01 AM by Slafon

    Listeners priority bug?

      I have created 500 Loader(s) to load some JPG file. Each listener added to the various events related to these downloads is assigned a priority 0.
      I also have created 1 URLLoader that download a small text file, and its listenerers are assigned a high prioriry (1000000).
      To create a test case, the JPG file I'm supposed to download (img.jpg) does not exists and the text file (text.txt) does exist, so that:
      -IOErrorEvent.IO_ERROR is supposed to trigger for the first 500 listeners (with some delay because it takes time for flash to get the info that the file does not exist, i.e. 404)
      -Event.COMPLETE is suppose to trigger for the text file does exist (very quickly as the file exists and is very small to download).

      Given the priorities, I would expect the latter to trigger before the former. However, in reality, what happens is that Flash first receives the 500 IOErrorEvent.IO_ERROR (it takes quite a few seconds) and then Event.COMPLETE! It seems like the Loader(s) are making blocking calls! Help!

      The demo can be executed here
      Please make sure that your browser's cache is empty when when executing the code a second time.

      The code can be found here and below:

      package {
      import flash.display.*;
      import flash.events.*;
      import flash.text.TextField;
      import flash.text.TextFormat;
      import flash.net.URLLoader;

      public class Main extends MovieClip {

      public var txt_loaded: Number;
      public var img_failed: Number;
      private var txt_loader: URLLoader;
      private var img_loaders: Array;
      public var dbgText: TextField;

      public function Main() {
      // Init counters.
      txt_loaded = img_failed = 0;
      // Init textField.
      var ft: TextFormat = new TextFormat();
      ft.size = 20;
      ft.color = 0xFFFFFF;
      dbgText = new TextField();
      dbgText.width = 500;
      dbgText.defaultTextFormat = ft;
      // Create 500 Loader(s) -- low priority (0) on their listeners.
      img_loaders = new Array();
      for (var i: Number = 0; i < 500; ++i) {
      var one_img_loader: Loader = new Loader();;
      one_img_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handleImgError, false, 0);
      var request:URLRequest = new URLRequest("no_img.jpg"); // This file does NOT exist.
      // Create a loader for the text file with high priority (1000000) on its listener.
      txt_loader = new URLLoader();
      var request:URLRequest = new URLRequest('text.txt'); // This file exists.
      request.method = URLRequestMethod.GET;
      txt_loader.addEventListener(Event.COMPLETE, handleTxtComplete, false, 1000000);

      private function handleImgError(event:IOErrorEvent):void {
      dbgText.text = "txt_loaded:" + txt_loaded + " img_failed:" + img_failed;

      private function handleTxtComplete(event:Event):void {
      dbgText.text = "txt_loaded:" + txt_loaded + " img_failed:" + img_failed;