Monday, April 26, 2010

Fit a image into a container in flex and Air

private function onCom(evt:Event):void
{

var t:Point = new Point(0,0);
var ptCanvasCenter:Point = new Point(width/2, height/2);
var canvasRatio:Number = myVbox.width / myVbox.height;
var ptImage:Point = new Point(0,0);
var ptImg:Point = new Point(0,0);


var iRatio:Number = evt.currentTarget.content.width / evt.currentTarget.content.height;

if (canvasRatio > iRatio)
{
trace("here in height");
myImage.height = myVbox.height
myImage.width = myImage.height * iRatio;
if(myImage.width < myVbox.width) { var newRatio = myVbox.width/myImage.width; myImage.width = myVbox.width; myImage.height = myImage.height*newRatio; } } else { myImage.width = myVbox.width; myImage.height = myImage.width / iRatio; if(myImage.height < myVbox.height) { var newRatio = myVbox.height/myImage.height; myImage.height = myVbox.height; myImage.width = myImage.width*newRatio; } } myImage.x = (myVbox.width - myImage.width)/2; myImage.y = (myVbox.height - myImage.height)/2; }

No comments:

Post a Comment