View Full Version : Getting width of an element added via addChild

09-05-2008, 12:29 AM
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");
thumbSpace = thumbSpace + imageLoader.width;
imageLoader.addEventListener(MouseEvent.CLICK, showPhoto);

10-15-2008, 09:22 PM
Hello Marilynn

I am having the same problem in the same way, I want to set the size of a swf file that I am is dynamically loaded from the server.

I tried to use the getChildByName() method to get this attribute but it is still not working.

it keeps coming up 0

for (var i:int = 0; i< xmlList.length(); i++) {
imageLoader = new Loader();
var imageHolder:holder = new holder();
imageLoader.load(new URLRequest(xmlList[i].attribute("source")));
imageHolder.cacheAsBitmap = true;
imageHolder.height = xmlList[i].attribute("height");
imageHolder.width = xmlList[i].attribute("width");
imageLoader.name = "image" +i;
imageText.text = xmlList[i];
imageLoader.mask = imageHolder;


I have a mask that goes over the swf files so I know that the you can set these properties when you ad the child from your library but it does not seem to work for files added from the server.

Does anyone out there know what is going on?:confused:

10-15-2008, 09:29 PM
This could be a bug that Adobe is working on right now


11-22-2008, 03:41 AM
I still don't have a solution to this