1 Reply Latest reply on Apr 23, 2010 7:06 AM by Ned Murphy

    I got problem in multi- image loading

    jacky_38

      var j:Number;
      var wid:Number=100;
      var imgLoader_show_board:Loader = new Loader();
      for (j=1; j<10; j++) {
      imgLoader_show_board.load(new URLRequest("marker_pic/rd_designed_marker_00"+ j + ".jpg"));
      imgLoader_show_board.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded_show_board);

      }
      function onImageLoaded_show_board(evt:Event):void {
      trace(j);
      addChild(imgLoader_show_board);

      imgLoader_show_board.width=75;
      imgLoader_show_board.height=75;
      imgLoader_show_board.x = wid;
      wid+=100;
      }

       

       

      I want to load 9 image at the same time,

      but finally there is the last image being loaded.

      should't I use for loop to do ??

        • 1. Re: I got problem in multi- image loading
          Ned Murphy Adobe Community Professional & MVP

          A Loader instance can only hold one element of content at a time.  Your code is continuously switching content of the same loader.  Try declaring your loader inside the for loop and see if that helps.  Your onLoaded function will need to be changed (or moved into the other function as well).

           

          var j:uint;
          var wid:Number=100;

          for (j=1; j<10; j++) {
                var imgLoader_show_board:Loader = new Loader();
               imgLoader_show_board.load(new URLRequest("marker_pic/rd_designed_marker_00"+ j + ".jpg"));
               imgLoader_show_board.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded_show_board);
               addChild(imgLoader_show_board);


               imgLoader_show_board.x = wid;
               wid+=100;
          }

           

          function onImageLoaded_show_board(evt:Event):void {
               trace(j); /// this is likely to show the same value ... the for loop is too fast
                evt.target.content.width=75;
                evt.target.content.height=75;
          }

           

          A for loop will probably finish before the first image is loaded, and there's no guarantee that things will load in any intended order.  You are probably better off not using a for loop, but instead creating a functional loop, where your completion of loading an image triggers the loading of the next image.