0

虽然我的代码非常大并且分散在许多文件中,但我基本上可以归结为:

我有一个功能可以做到这一点:

var loadedScript:Loader;
function load():void{
    loadedScript = new Loader();
    // loadedScript is initilized somewhere and other stuff
    loadedScript.loadBytes(bytes, context);
    loadedScript.contentLoaderInfo.addEventListener(Event.COMPLETE, scriptLoaded, false, 0, true);
}

当我以这样的方式连续调用此函数 2 次时,它被称为 2。loadedScript.loadBytes(字节,上下文)之前的时间;从1.时间可以完成,那么“scriptLoaded”方法只为2.时间调用,而不是1.时间

那么,这是来自 loadedScript.loadBytes(bytes, context); 的故意行为吗?方法或错误,我能以某种方式绕过它吗?

4

1 回答 1

2

you could ofcourse create a loader-queue, something like this:

var queue:Array = new Array();
function load(bytesToLoad:*):void {
    queue.push(bytesToLoad);
    processQueue();
}

function processQueue():void {
    //check if items are on queue
    if (queue.length > 0) {
        //create a loader
        var ldr:Loader = new Loader();
        //add event for loading complete
        ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, scriptLoaded, false, 0, true);
        //load the bytes (get first item from the queue, which contains the bytes to load)
        ldr.loadBytes(queue.shift(), context);
    }
}

function scriptLoaded():void {
     //do stuff

     //process next item in queue
     processQueue();
}
于 2013-08-19T11:11:23.953 回答