Proportional Scaling Techniques


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*
  2.  
  3. You can responds to any stage resize event by proportionally scaling the image to fill the stage. Since scaleX and scaleY are percentages, it's just a matter of figuring out which property is larger and making the two equal. By swapping the scale comparison from greater than to less than, the object will scale proportionally to fit the larger of the two dimensions given. This kind of calculation is handy when you need to fit items of variable dimensions into a fixed space.
  4.  
  5. */
  6.  
  7. // set image dimensions to match stage or the object you want to scale to;
  8. image.width = stage.stageWidth; // Or object.width
  9. image.height = stage.stageHeight; // Or object.height
  10.  
  11. // choose the larger scale property and match the other to it;
  12. ( image.scaleX < image.scaleY ) ? image.scaleY = image.scaleX : image.scaleX = image.scaleY;
  13.  
  14. // choose the smaller scale property and match the other to it;
  15. ( image.scaleX > image.scaleY ) ? image.scaleY = image.scaleX : image.scaleX = image.scaleY;

URL: http://en.wikipedia.org/wiki/Image_scaling

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.