Autosize image?

hi,
is it possible to display images in a frame or something in flash, so that the images automaticly fill the frame or autoscale ?

this is what I would like to happen:
if an image on the server is bigger than an object or frame in flash, it automaticly displays the image smaller so that it fits the box, frame whatever.
that way I don’t have to resize my pictures manually.

thx

i don’t think there’s a checkbox you can check, but you can certainly accomplish this with some actionscript.

let’s say there’s a holder clip (named “holder”), we’ll use that to load the photos into.

to load a pic, we’ll use three functions. one will get a new picture by creating a movie in “holder” (which will overwrite the previous pic) and loading the jpeg into the newly created clip. the next will check the progress of the loading. and finally once the loading is comlplete, one to size the loaded pic.

it’ll go something like this:


// let's create holder clip with code
_root.createEmptyMovieClip("holder",0);

// here's the functions we'll use
function newPic(jpeg){
	_root.holder.createEmptyMovieClip("photo",0);
	loadMovie(jpeg, _root.holder.photo);
	_root.holder.onEnterFrame = loadingActions;
}

function loadingActions(){
	var l,t;
	l = _root.holder.photo.getBytesLoaded();
	t = _root.holder.photo.getBytesTotal();
	if(l>0 && l==t){
		_root.sizePic();
		_root.holder.onEnterFrame = null;
	}
}

// say the size you want to fill is 300 x 300
function sizePic(){
	var pic = _root.holder.photo;
	// use the largest side to size by
	var side = Math.max(pic._width,pic._height);
	pic._xscale = pic._yscale = 300/side * 100;
}

to load a jpeg call newPic() with the name (and path) of the jpeg to load passed as a string. ie:


on(release){
	newPic("pics/myGreatPhoto.jpg");
}

if you want to fill a shape that’s not a square, the sizePic function will need to be a little more complicated to work with both axis, but this should give you a starting point.

good luck!