如何控制图像加载到 AS3 中的精灵

How can I control the loading of images to a sprite in AS3

如何控制将图像加载到 sprite 我有一个向量,其中有我要加载的图像的名称,但要执行我使用 contentLoaderInfo 的循环 偶数初始化 属性 它加载随机图像,它们没有按它们的顺序加载在数组中。 我无法按照我尝试过 Even.init Even.complete 的排列顺序将图像添加到舞台上,而且我无法得到我希望的结果,否则我怎么能这样做

var lista_nombresPises:Array = new Array("ar.png","br.png","ch.png","co.png","it.png","ja.png","mx.png","pa.png","sp.png","US.png");
var nombresPaises_sprites:Array = [];
for(i=0;i<lista_nombresPises.length;i++){
    nombresPaises_sprites.push(new Sprite);
    nombresPaises_sprites[i].name = "pais"+(i+1);//Le asignamos el nombre
    direc= new URLRequest("Palabras/Paises/"+lista_nombresPises[i]);//Fue creado en el login
    var loadPaises:Loader = new Loader();
    loadPaises.load(direc);
    loadPaises.contentLoaderInfo.addEventListener(Event.INIT,cargaImagenBandera);
}
var indi = 0;
var posy = 118;
function cargaImagenBandera(eve:Event):void{
    nombresPaises_sprites[indi].addChild(eve.target.content);
    nombresPaises_sprites[indi].x = 65;
    nombresPaises_sprites[indi].y = posy;
    posy=posy+60;
    addChild(nombresPaises_sprites[indi]);
    indi++;
}

//Cargamos las Banderas de los paises
var lista_Banderas:Array = new Array("banAr.png","banBr.png","banCh.png","banCo.png","banIt.png","banJa.png","banMx.png","banPa.png","banSp.png","banUs.png");
var banderas_sprites:Array = [];
for(i = 0; i<lista_Banderas.length;i++){
    var direcBandera:URLRequest = new URLRequest("Palabras/Paises/Banderas/"+lista_Banderas[i]);
    banderas_sprites.push(new Sprite);
    var loaderBandera:Loader = new Loader();
    loaderBandera.load(direcBandera);
    loaderBandera.contentLoaderInfo.addEventListener(Event.INIT,cargarBanderas);
}

如果理解不正确,我想做的是图像始终按特定顺序加载。例如,名称为 img1 的图像应始终首先加载。设法让它们按照数组中的顺序加载

加载是 AS3 中的异步操作。这意味着如果您批量请求加载少量文件,它们不一定会以完全相同的顺序完成加载。

但是,您甚至不需要等待它们完成加载,也就是说,如果您知道图像大小,不打算巧妙地自动调整行的大小,不打算处理错误,等等。您可以提前安排它们,然后设置它们加载。外部内容将在加载并可用时显示。

var baseURL:String = "Palabras/Paises/";
var aList:Array = [
    "ar.png","br.png","ch.png","co.png","it.png",
    "ja.png","mx.png","pa.png","sp.png","US.png"
];

for (var i:int = 0; i < aList.length; i++)
{
    // Create required objects.
    var aRequest:URLRequest = new URLRequest;
    var aLoader:Loader = new Loader;
    var aWrap:Sprite = new Sprite;

    // Form a proper URL.
    aRequest.url = baseURL + aList[i];

    // Arrange the (currently) empty container
    // to its designated position.
    aLoadex.x = 65;
    aLoader.y = 118 + 60 * i;

    // Start loading the external resource.
    aLoader.load(aRequest);

    // Loader subclasses DisplayObject and can be added
    // to the stage just as any other. It will display the
    // content it loads when the content is available.
    aWrap.addChild(aLoader);
    addChild(aWrap);

    // Replace the filename on the list with the
    // corresponding Loader instance, if you need them
    // in the future for anything.
    aList[i] = aWrap;
}