Skip to main content
Inspiring
May 20, 2006
Answered

Fitting a picture to fill a box

I have a layout that I've created in Flash that involves bringing a picture in dynamically into a box. I can get it to come in at the top left without a problem, but ideally I need it to fill the height of the box (if it's a portrait picture) or the width (if it's landscape).

The box's dimensions are 555px wide x 420px height

If it is a portrait picture, then it needs to be centred horizontally.

I'm so used to pressing a couple of buttons in InDesign (fit content proportionally and then centre in box) that I forget everything technical in Flash requires so much thought!

Any help would be most appreciated.

Andy
This topic is closed to new replies. Start a new post to keep the conversation going.
TillerCorrect answer
Inspiring
May 20, 2006
It can't 'sense' it, you would have to indicate it somehow. Maybe through special names of the files, e.g. "pic1_P.jpg" vs. "pic2_L.jpg" (P for portrait, L for landscape), so Flash could check what's between _ and . and react accordingly. Maybe it would also be possible to know it from the image dimensions, if there are big differences between portrait and landscape pictures.
How do you load these pictures? If you have an external file (xml) with the filenames, you could store this info along the names, that should be the simplest way.

Many thanks for that... we'll probably be using a combination of PHP and XML so between those I'm sure we'll find a solution.

Andy

4 replies

Inspiring
May 20, 2006
To scale the picture and center it when it's loaded, you can use simple percent calculation:
box.pic._yscale = box._height * 100 / box.pic._height;
box.pic._x = box._width / 2 - box.pic._width / 2;
This assumes the picture is loaded in an MC 'pic' inside the 'box' MC, and it scales just one dimension, which could lead to distortion. To keep the original ratio, just scale the y dimension with the same factor.
This would be the portrait scaling, landscape would be similar, just with the _width properties. You would have to know which type of picture was loaded before.

hth,
blemmo
Translate
TillerAuthor
Inspiring
May 20, 2006
Hi Blemmo,

Thanks very much for your reply - is there any way Flash can sense what kind of picture it is when it's loaded?

Andy
Translate
Inspiring
May 20, 2006
It can't 'sense' it, you would have to indicate it somehow. Maybe through special names of the files, e.g. "pic1_P.jpg" vs. "pic2_L.jpg" (P for portrait, L for landscape), so Flash could check what's between _ and . and react accordingly. Maybe it would also be possible to know it from the image dimensions, if there are big differences between portrait and landscape pictures.
How do you load these pictures? If you have an external file (xml) with the filenames, you could store this info along the names, that should be the simplest way.
Translate