alon900
June 25th, 2009, 08:18 AM
Hi there,
Can any1 please tell me how can i load an image to an exact size in the movie clip ?
lets say i have an img which is 1000X1000 and i want to leave it at the same proportion but display it at 800X800
theCodeBot
June 25th, 2009, 08:55 AM
Use simple math and the scaleX, scaleY, width, and height properties of all DisplayObjects, like so:
var image:Loader = new Loader();
var _url:URLRequest = new URLRequest("location_of_image.jpg");
image.contentLoaderInfo.addEventListener(Event.COM PLETE, loaded);
image.load(_url);
var originalWidth:Number = 0;
var originalHeight:Number = 0;
var targetWidth:Number = 800;
var targetHeight:Number = 800;
var keepProportions:Boolean = true;
function loaded (event:Event):void
{
originalWidth = image.width;
originalHeight = image.height;
image.scaleX = targetWidth/originalWidth;
if(keepProportions) {
//If we're keeping in proportion, scale together,
//And make sure that it ends up fitting in the box
image.scaleY = image.scaleX;
if (image.scaleY*originalHeight > targetHeight) {
image.scaleY = targetHeight/originalHeight;
image.scaleX = image.scaleY;
}
}
else {
//If we aren't keeping proportions, stretch
image.scaleY = targetHeight/originalHeight;
}
}
alon900
June 25th, 2009, 09:59 AM
Thanks alot !! :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.