scale image on browser resize
I am wondering how would I scale an image on browser resize with minimum and maximum width and height parameters?
I know how to use the Event.RESIZE function to make my image proportional with the browser using stage.stageWidth/Height, but I am trying to figure out a way to have a movieclip or image scale up or down to a certain dimension s开发者_开发技巧uch as on browser resize the image max would be 640x480 and the minimum being 320x240. Anyone have a link or any suggestions? I can't find any forum with the exact answer. Thanks.
Use Math.min() and Math.max() to clamp the values for your width and height. I'm assuming you want the image to scale proportionally.
var w : Number = Math.max(320, Math.min(stage.stageWidth, 640));
var scaleRatio : Number = w / 640;
var h : Number = 480 * scaleRatio;
myImage.width = w;
myImage.height = h;
精彩评论