照片加载顺序搞乱了的AS3

编程入门 行业动态 更新时间:2024-10-24 10:26:56
本文介绍了照片加载顺序搞乱了的AS3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经创建了一个容器(或影片剪辑),将在顺序和显示在舞台上添加照片。然而,由于不同的文件大小,它会首先添加最小的文件大小的照片。我怎么能解决这个问题。请参见下面

样品code

// image0.jpg - > 3K // image1.jpg - > 2K // image2.jpg - > 1K // image3.jpg - > 2K // image5.jpg - > 1K VAR photoPath:阵列=新的Array(); VAR photoContainer:影片剪辑=新的MovieClip(); photoPath.push('im​​age0.jpg'); photoPath.push('im​​age1.jpg'); photoPath.push('im​​age2.jpg'); photoPath.push('im​​age3.jpg'); photoPath.push('im​​age4.jpg'); 对于(VAR I = 0; I< photoPath.length;我++) {     VAR装载机:装载机=新的Loader();     loader.load(的URLRequest(photoPath [I]));     loader.contentLoaderInfo.addEventListener(引发Event.COMPLETE,photoLoaded); } 功能photoLoaded(五:事件):无效 {     photoContainer.addChild(e.target.content); } //输出会看起来像(IMAGE2,image5,此搜索,的Image3,image0),而不是0,1,2,3,4,5的

解决方案

有相当多的方式来处理这个问题,可能要改造你目前的code中的最简单的方法是将装载机添加到图像显示,因为它被实例化。这将保证它们放置在photoContainer以正确的顺序。如果你确实需要的位图本身是在图像显示,相对于装载机本身,你可以在你的photoLoaded方法解决这个问题:

进口flash.display.Loader; VAR photoPath:阵列=新的Array(); VAR photoContainer:影片剪辑=新的MovieClip(); photoPath.push('im​​age0.jpg'); photoPath.push('im​​age1.jpg'); photoPath.push('im​​age2.jpg'); photoPath.push('im​​age3.jpg'); photoPath.push('im​​age4.jpg'); 对于(VAR I = 0; I< photoPath.length;我++) {     VAR装载机:装载机=新的Loader();     photoContainer.addChild(装载机); //装载机添加到photoContainer     loader.load(新的URLRequest(photoPath [I]));     //你实际上只需要听下面完整的,如果你要替换其内容的装载机     loader.contentLoaderInfo.addEventListener(引发Event.COMPLETE,photoLoaded); } 功能photoLoaded(五:事件):无效 {     VAR装载机:装载机= e.target.loader;     VAR指数:INT = photoContainer.getChildIndex(装载机);     //这将在同一顺序装载器最初被加入加入载入的内容     photoContainer.addChildAt(loader.content,索引);     photoContainer.removeChild(装载机); }

I have created a container(or a movieclip) that will add the photos in order and display on the stage. however, because of the different file size, it will add the smallest file size photo first. how i can solve this issue. please see the sample code below

// image0.jpg -> 3k // image1.jpg -> 2k // image2.jpg -> 1k // image3.jpg -> 2k // image5.jpg -> 1k var photoPath:Array = new Array(); var photoContainer:MovieClip = new MovieClip(); photoPath.push('image0.jpg'); photoPath.push('image1.jpg'); photoPath.push('image2.jpg'); photoPath.push('image3.jpg'); photoPath.push('image4.jpg'); for(var i = 0; i < photoPath.length; i++) { var loader:Loader = new Loader(); loader.load(URLRequest(photoPath[i])); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, photoLoaded); } function photoLoaded(e:Event):void { photoContainer.addChild(e.target.content); } //output will looks like (image2,image5,image1,image3,image0) instead of 0,1,2,3,4,5

解决方案

There are quite a few ways to handle this issue, probably the easiest way to retrofit your current code is to add the Loader to the displaylist as it is instantiated. This will guarantee that they're placed in the photoContainer in the correct order. If you absolutely need the bitmap itself to be in the displaylist as opposed to the loader itself, you can address this in your photoLoaded method:

import flash.display.Loader; var photoPath:Array = new Array(); var photoContainer:MovieClip = new MovieClip(); photoPath.push('image0.jpg'); photoPath.push('image1.jpg'); photoPath.push('image2.jpg'); photoPath.push('image3.jpg'); photoPath.push('image4.jpg'); for(var i = 0; i < photoPath.length; i++) { var loader:Loader = new Loader(); photoContainer.addChild(loader); //add the loader to photoContainer loader.load(new URLRequest(photoPath[i])); //you only actually have to listen for complete below if you want to replace the loader with its contents loader.contentLoaderInfo.addEventListener(Event.COMPLETE, photoLoaded); } function photoLoaded(e:Event):void { var loader:Loader = e.target.loader; var index:int = photoContainer.getChildIndex(loader); // this will add the contents of the loader in the same order the loader was originally added photoContainer.addChildAt(loader.content, index); photoContainer.removeChild(loader); }

更多推荐

照片加载顺序搞乱了的AS3

本文发布于:2023-11-23 15:47:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622009.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:顺序   加载   照片

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!