...

View Full Version : Unifying thumbnail sizes



marilynn.fowler
04-29-2008, 10:49 PM
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:


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);
}
}

gnomeontherun
04-30-2008, 02:39 AM
I don't know AS3, but here is a tutorial.
http://vilebody.wordpress.com/2007/11/07/flash-actionscript-3-proportional-image-resizing/

marilynn.fowler
04-30-2008, 03:04 AM
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:


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?

gnomeontherun
04-30-2008, 04:13 AM
Ahh I understand what you mean. I'm not sure on semantics of code, but something like this in theory might do it.


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);
}
}

marilynn.fowler
05-02-2008, 10:10 PM
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.

gnomeontherun
05-02-2008, 10:18 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum