开发者

flash as3 movieClip loader doesn't load in numerical sequence

I am loading an array of movie clips and adding them to the stage with flash as3, but the problem is that the movie clips are added to the stage as soon as they finish loading, and not in order of there position in the array, so the order on screen appears messed up. How do I ensure that they are added to the stage in the same order that their references exist in the URL? Here is my code:

var currentLoaded:int = 0;

function loadThumbs(){
    for (var i in project_array){
        var thumbLoader:Loader = new Loader();
        thumbLoader.load(new URLRequest(project_array[i].project_thumb));
        thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded);
    }
}

function thumbLoaded(e:Event):void {
    project_array[currentLoaded].projectThumb.thumbHolder.addChild(e.target.content);
    admin.slideHolder.addChild(project_array[currentLoaded].pr开发者_高级运维ojectThumb);
    currentLoaded++;
}


Well I was just typing the same solution... to Load in some specific order, you have to make it recursive. You may try the loadermax library from greensock. Is rock solid, fast and lightweight. Besides that very easy to use and you can set the ammount of parallel loading treads. you can find it here


Assets might load faster than others, so something like this might help...

  function thumbLoaded(e:Event):void {
      project_array[currentLoaded].projectThumb.thumbHolder.addChild(e.target.content);
      currentLoaded++;
      if(currentLoaded>=project_array.length){
        addAssetsToStage();
      }
    }

    function addAssetsToStage():void{
      for(var i:int=0;i<project_array.length;i++)
      {
        admin.slideHolder.addChild(project_array[i].projectThumb);
      }   
    }


Well, I suppose this works - but if anyone figures out a way to do this without waiting for each previous image to load before starting another load, please let me know!

    var currentLoaded:int = 0;

function loadThumbs(){
    if (currentLoaded < project_array.length){
        var thumbLoader:Loader = new Loader();
        thumbLoader.load(new URLRequest(project_array[currentLoaded].project_thumb));
        thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded);
    }
}

function thumbLoaded(e:Event):void {
    project_array[currentLoaded].projectThumb.thumbHolder.addChild(e.target.content);
    admin.slideHolder.addChild(project_array[currentLoaded].projectThumb);
    currentLoaded++;
    loadThumbs();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜