/ Published in: ActionScript 3
Scale an object with fixed aspect ratio to fit in a specific area.
Expand |
Embed | Plain Text
function scaleByRatio(obj:DisplayObject, maxWidth:Number, maxHeight:Number):void { if (obj.width > obj.height) { obj.height = (maxWidth * obj.height) / obj.width obj.width = maxWidth; }else if (obj.height > obj.width) { obj.width = (maxHeight * obj.width) / obj.height obj.height = maxHeight; }else { obj.width = maxWidth; obj.height = maxHeight; } }
You need to login to post a comment.
