marilynn.fowler
09-04-2008, 11:29 PM
How do I get the width of a thumb that's been dynamically added to the stage via addChild? When I trace imageLoader.width I get 0. I ask this because the thumbnails will be varying widths.
var imageLoader:Loader;
var xml:XML;
var xmlList:XMLList;
var fadeTween:Tween;
var thumbSpace:int = 0;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("data/images.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event:Event):void {
xml = XML(event.target.data);
xmlList = xml.children();
for(var i:int = 0; i < xmlList.length(); i++) {
imageLoader = new Loader();
imageLoader.load(new URLRequest(xmlList[i].attribute("thumb")));
imageLoader.x = (thumbSpace);
imageLoader.y = 0;
imageLoader.name = xmlList[i].attribute("source");
addChild(imageLoader);
thumbSpace = thumbSpace + imageLoader.width;
trace(thumbSpace);
imageLoader.addEventListener(MouseEvent.CLICK, showPhoto);
}
}
var imageLoader:Loader;
var xml:XML;
var xmlList:XMLList;
var fadeTween:Tween;
var thumbSpace:int = 0;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("data/images.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event:Event):void {
xml = XML(event.target.data);
xmlList = xml.children();
for(var i:int = 0; i < xmlList.length(); i++) {
imageLoader = new Loader();
imageLoader.load(new URLRequest(xmlList[i].attribute("thumb")));
imageLoader.x = (thumbSpace);
imageLoader.y = 0;
imageLoader.name = xmlList[i].attribute("source");
addChild(imageLoader);
thumbSpace = thumbSpace + imageLoader.width;
trace(thumbSpace);
imageLoader.addEventListener(MouseEvent.CLICK, showPhoto);
}
}