Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts

    Getting width of an element added via addChild

    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.

    Code:
    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);
    		}
    }
    Last edited by marilynn.fowler; 09-05-2008 at 08:45 PM.
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx

  • #2
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Same Problem

    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

    Code:
    	for (var i:int = 0; i< xmlList.length(); i++) {
    		imageLoader = new Loader();
    		var imageHolder:holder = new holder();
    		addChild(imageHolder);
    		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];
    		addChild(imageLoader);
    		imageLoader.mask = imageHolder;
    		trace(getChildByName('image'+i).width);
    		
    	}
    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?

  • #3
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Could be a bug

    This could be a bug that Adobe is working on right now

    http://bugs.adobe.com/jira/browse/FP-280

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts
    I still don't have a solution to this
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •