我似乎在这里遇到问题,在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);
}
}
答案 0 :(得分: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!!!");
}
}