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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts

    Unifying thumbnail sizes

    Let's say I have thumbnails in an XML file of varying sizes. I want them all to line up next to each with no spaces other AND I want them to resize proportionally to be the same height. How do I modify the code I'm currently using?

    The function I currently use allows me to line them up if they're all the same width, which in this case was 60:

    Code:
    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 = (i * 60);
    		imageLoader.y = 0;
    		imageLoader.name = xmlList[i].attribute("source");
    		addChild(imageLoader);
    		imageLoader.addEventListener(MouseEvent.CLICK, showPhoto);
    		}
    }
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    I don't know AS3, but here is a tutorial.
    http://vilebody.wordpress.com/2007/1...mage-resizing/

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts
    Thanks, Jeremy. That will be very handy.

    I'm actually more concerned about how to get them next to one another when they have differing widths. I think I want to initially set the loader width to zero, then every time it loops through to add the child it evaluates the new width and sets the X value. So would it look like this:

    Code:
    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 = (i + imageLoader.width);
    		imageLoader.y = 0;
    		imageLoader.name = xmlList[i].attribute("source");
    		addChild(imageLoader);
    		imageLoader.addEventListener(MouseEvent.CLICK, showPhoto);
    		}
    }
    Would the imageLoader width expand like an accordion every time through?
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx

  • #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Ahh I understand what you mean. I'm not sure on semantics of code, but something like this in theory might do it.

    Code:
    function xmlLoaded(event:Event):void {
    	xml = XML(event.target.data);
    	xmlList = xml.children();
    	
            var imagePosition:Number = 0;
    
    	for(var i:int = 0; i < xmlList.length(); i++) {
    		imageLoader = new Loader();
    		imageLoader.load(new URLRequest(xmlList[i].attribute("thumb")));
    		imageLoader.x = (imagePosition + imageLoader.width);
    		imageLoader.y = 0;
                    imagePosition += imageLoader.width;
    		imageLoader.name = xmlList[i].attribute("source");
    		addChild(imageLoader);
    		imageLoader.addEventListener(MouseEvent.CLICK, showPhoto);
    		}
    }

  • #5
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts
    Sadly it didn't work. The images are really bunched up except for the last one. But at least I didn't get an error message.
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx

  • #6
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Describe bunched up...on top of eachother? Can you show me the entire FLA or an example of what is happening?

    Flash is so visual and can be hard to know what is wrong without seeing the results.


  •  

    Posting Permissions

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