Oct
13
2008
Resizing width and height proportionately
Posted by: Keith H in ActionScript 3, tags: Constrain Proportion, Porportional, ResizeIf you use Photoshop you probably appreciate the "Constrain Proportions" checkbox found in some of the application's dialogs and menus.
I like to have this same ability when I'm writing ActionScript to resize objects proportionately too.
Here I use the functions to set the sizes so when I set width, height is changed accordingly.
The same for setting height, the width is changed accordingly.
*Note: I set the inputs to limit the width and height to 500.
Here are two functions for performing proportional resizing by both width and height...
/*--------------------------------------------- Resize proportionately by width. Returns an Object with new proportionate "width" and "height" properties. After passing the current width, current height and a new width. -----------------------------------------------*/ function constrainSizeToWidth(oldW:Number,oldH:Number,newW:Number):Object { return {width:newW,height:newW / oldW * oldH}; } /*--------------------------------------------- Resize proportionately by height. Returns an Object with new proportionate "width" and "height" properties. After passing the current width, current height and a new height. -----------------------------------------------*/ function constrainSizeToHeight(oldW:Number,oldH:Number,newH:Number):Object { return {width:newH / oldH * oldW,height:newH}; }
Entries (RSS)