title: How to fix closure problem in ActionScript 3 (AS3)
body: <p>In the code below I'm trying to load some images and put them in the stage as soon as they get individually loaded. But it is bugged since only the last image is displayed. I suspect it's a closure problem. How can I fix it? Isn't the behaviour of closures in AS3 the same as in Java Script ?</p>
  
  <pre><code>var imageList:Array = new Array();
  imageList.push({'src':'image1.jpg'});
  imageList.push({'src':'image2.jpg'});
  var imagePanel:MovieClip = new MovieClip();
  this.addChildAt(imagePanel, 0);
  
  for (var i in imageList) {
      var imageData = imageList[i];
      imageData.loader = new Loader();
  
      imageData.loader.contentLoaderInfo.addEventListener(
          Event.COMPLETE, 
          function() {
              imagePanel.addChild(imageData.loader.content as Bitmap);
              trace('Completed: ' + imageData.src);             
          });
  
      trace('Starting: ' + imageData.src);
      imageData.loader.load(new URLRequest(imageData.src));   
  }
  </code></pre>