I’m not the first one who struggle with this problem, I know, but I just can’t find out how to do!
I have a loop where I load a couple of images and I want to place them in the y-axis on stage, with 20 pixels space between them. To do this I have to know the height of each image, but as you know, I can’t get the image height before it completed loading.
I really don’t want to do one loop for the loading, and another loop for the placing. Can you do it in another way?
for (var i=0;i<productXml.productCategory.product.length();i++) {
var product_mc:MovieClip = new MovieClip();
var imgLoader:Loader = new Loader();
imgLoader.name = "imgLoader";
product_mc.addChild(imgLoader);
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadImg);
imgLoader.load(new URLRequest("products/" + productXml.productCategory.product*.imgUrl));
product_mc.y = placeProduct; // placeProduct is 0 from start
placeProduct += product_mc.height + 20; // product_mc.height is always 0 because the image haven't complete loading at this time
addChild(product_mc);
}
}
function loadImg(e:Event): void {
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
var dispObj:DisplayObject = loaderInfo.content;
};