0

I am trying, adding it to an arrangement, but only the last image added appears to me, the goal is to have several images on screen at the same time.

So far this is my Code

import flash.display.Sprite;

var sprites:Array = [];
var lista_paises_imagenes:Array = new Array("ar.png","br.png","ch.png","co.png");
for(var i = 0;i < lista_paises_imagenes.length;i++){
    var direcimg:URLRequest = new URLRequest("Palabras/Paises/"+lista_paises_imagenes[i]);
    var objload:Loader = new Loader();
    sprites.push(new Sprite());
    objload.load(direcimg);
    objload.contentLoaderInfo.addEventListener(Event.COMPLETE,CargaImg);
}

var xx:Number = 0;
var xy:Number = 0;
function CargaImg(eve:Event):void{
    sprites[xx].addChild(objload.content);
    sprites[xx].x = xy;
    sprites[xx].y = 255;
    //sprites[xx].height = 90;
    //sprites[xx].width = 90;
    addChild(sprites[xx]);
}
trace(stage.numChildren)
trace(sprites.length);

As a result of numChildren on finishing only 1 object on the stage Imgae

  • 1
    The loading is asynchronous operation, that means that **Event.COMPLETE** handler is invoked some time later, after the initial loop is finished. That, in turn, means, that **objload** variable will always contain the reference to very last **Loader**. So, instead of **objload.content** you should address **eve.target.content** because **eve.target** will point to the **LoaderInfo** instance, that is invoking the event. Also, I advise to use the **Event.INIT** event rather than **Event.COMPLETE**, because **INIT** is invoked when content is actually ready, which is later than **COMPLETE** – Organis Jun 13 '20 at 18:10
  • Thanks it helped me the eve.target.content I can already add the other images – Rodrigo Gutierrez Jun 13 '20 at 18:43

0 Answers0