0

我在这里似乎有一个问题,在 FOR 循环中加载多个图像。

这是我的代码:

我正在读取一个 XML 文件以获取我需要添加的缩略图的位置。然后我浏览整个列表(现在我浏览前 5 个元素)并将它们添加到名为“popUpImgGroup”的 TileGroup 中。

出于某种原因,我只得到了 1 个可见的拇指,但实际上添加了 5 个元素。

任何的想法?

谢谢!:)

private function loadPopUpThumbs():void{
            for(var i:int=1; i<=5; i++){
                var thumbImg:Image = new Image();
                var _loader:Loader = new Loader();

                _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void{ 
                    thumbImg.source = e.currentTarget.content;
                });
                _loader.load(new URLRequest(encodeURI(popUpXMLList.(attribute('nr')==i.toString()).@thumbURL)));

                popUpImgGroup.addElement(thumbImg);

                thumbImg.width = 90;
                thumbImg.height = 90;
                thumbImg.scaleMode = "letterbox";
                thumbImg.verticalAlign = "bottom";
                thumbImg.smooth = true;
                thumbImg.addEventListener(MouseEvent.CLICK, function(evt:MouseEvent){ popUpThumbClicked(popUpXMLList.(attribute('nr')==i.toString()).@fullURL)});

                trace("Thumb added: " + popUpXMLList.(attribute('nr')==i.toString()).@thumbURL);
            }
        }
4

1 回答 1

1

找到了答案-.-

当我为解决方案而苦苦挣扎时,我讨厌它,并在此处发布问题只是为了解决问题。很抱歉打扰你们=)这是我最终做的事情:

            private function loadPopUpThumbs():void{
            if(curThumbImg <= totThumbImg){
                var thumbImg:Image = new Image();
                var _loader:Loader = new Loader();
                var imageNr:int = curThumbImg;

                _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void{ 
                    thumbImg.source = e.currentTarget.content;

                    popUpImgGroup.addElement(thumbImg);

                    thumbImg.width = 90;
                    thumbImg.height = 90;
                    thumbImg.scaleMode = "letterbox";
                    thumbImg.verticalAlign = "bottom";
                    thumbImg.smooth = true;
                    thumbImg.id = "thumbImg" + imageNr;
                    thumbImg.addEventListener(MouseEvent.CLICK, function(evt:MouseEvent):void{ popUpThumbClicked(popUpXMLList.(attribute('nr')==imageNr.toString()).@fullURL)});

                    trace("Thumb added: " + popUpXMLList.(attribute('nr')==imageNr.toString()).@thumbURL);
                    curThumbImg++;
                    loadPopUpThumbs();
                });

                _loader.load(new URLRequest(encodeURI(popUpXMLList.(attribute('nr')==imageNr.toString()).@thumbURL)));

            }else{
                trace("DONE Adding thubs!!!");
            }
        }
于 2013-03-20T13:42:12.050 回答