flash as3 movieClip 加载器未按数字顺序加载

发布于 2024-10-19 01:13:37 字数 678 浏览 5 评论 0原文

我正在加载一个影片剪辑数组并使用 flash as3 将它们添加到舞台上,但问题是影片剪辑在完成加载后立即添加到舞台上,而不是按照数组中位置的顺序,所以屏幕上的顺序显得混乱。如何确保它们按照其引用在 URL 中存在的顺序添加到舞台中?这是我的代码:

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].projectThumb);
    currentLoaded++;
}

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].projectThumb);
    currentLoaded++;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

皓月长歌 2024-10-26 01:13:38

好吧,我只是输入相同的解决方案......
要以某种特定顺序加载,您必须使其递归。
您可以尝试 greensock 的 loadermax 库。坚如磐石、快速且轻量。
除此之外,非常易于使用,您可以设置并行装载踏板的数量。
您可以在此处找到它

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

飞烟轻若梦 2024-10-26 01:13:38

资产的加载速度可能比其他资产更快,所以这样的事情可能会有所帮助......

  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);
      }   
    }

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);
      }   
    }
一腔孤↑勇 2024-10-26 01:13:38

好吧,我想这可行 - 但如果有人想出一种方法来做到这一点,而无需等待每个先前的图像加载后再开始另一个加载,请告诉我!

    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();
}

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();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文