Your Ad Here

Posted By

sidneydekoning on 05/14/09


Tagged


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

dpollen
toxin20
Pingpongbal
davidino1978
dubogii


Proportional Scaling Techniques


 / Published in: ActionScript 3
 

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

  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;

Report this snippet  

You need to login to post a comment.