且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何用foreach和进度条将图片添加到一个容器雪碧?

更新时间:2023-12-02 22:22:16

发生了什么事是你已经填充了变量 ldrAnim 多发性次,创造了新的 AllLoader 各一次。当你调用 removeChild之(),能正常工作的第一次(在某种程度上 - 它会删除您创建的最后一个,不管是装还是不相匹配的音乐) 。当你调用 removeChild之()再次,你调用它的同一个你删除(这已不再是你调用它的对象是儿童)

What's happening is that you have populated the variable ldrAnim multipe times, creating a new AllLoader each time. When you call removeChild(), this works fine the first time (sort of--it will remove the last one you created, whether it matches the image that loaded or not). When you call removeChild() again, you're calling it for the same one you just removed (which is no longer a child of the object you're calling it on).

要解决这个问题的方法之一是使用词典和准每个 AllLoader 装载机该图像。当完成事件触发,然后你可以查找 Alloader 根据事件的性质,将其取下。

One way to fix this is to use a Dictionary and associate each AllLoader with the Loader for that image. When the COMPLETE event fires, you can then look up the Alloader based on the event's properties and remove it.

另一种解决方案是写一个类,包装了一个 AllLoader 装载机,然后处理之间的过渡2本身当装载加载完毕。

Another solution is to write a Class that wraps an AllLoader and a Loader and then handles the transition between the two itself when the Loader has finished loading.

这看起来是这样的:


public class LoadSwitcher extends Sprite{
   protected var loader:Loader;
   protected var allLoader:AllLoader;
   public function loadSwitcher(url) {
       super();
       loader = new Loader();
       var request:URLRequest = new URLRequest(url);
       loader.contentLoaderInfo.addEventListener(Event.COMPLETE, switchLoaders);
       allLoader = new AllLoader(loader);//assume AllLoader now has logic to watch the loader for % complete
       loader.load(request);
       addChild(allLoader);
   }
   protected function switchLoaders(e:Event):void {
      removeChild(allLoader);
      addChild(loader);
   }
}

然后,只需创建和位置的其中之一为您的相册各一人。

Then just create and position one of these for each one of your albums.