Posted By

orazal on 08/22/07


Tagged

math actionscript


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

n00ge
arala22
shoffa
hi2shamika20
orazal


resizeProportionally


 / Published in: ActionScript
 

  1. /**
  2.  * Determines which size is smaller and resizes the other size to the same percentage
  3.  *
  4.  *@param clip The movieclip to resize
  5.  *@param w The maximum width to resize to
  6.  *@param h The maximum height to resize to
  7.  *@param overflow A boolean to determine if the image should overflow the visual area (no blank space)
  8.  */
  9. function resizeProportionally(clip:MovieClip, w:Number, h:Number, overflow:Boolean):Void {
  10. // Determine percentage
  11. var hPer:Number = w/clip._width;
  12. var vPer:Number = h/clip._height;
  13. if (overflow) {
  14. // Use biggest
  15. var percent:Number = Math.max(hPer, vPer);
  16. } else {
  17. // Use smallest
  18. var percent:Number = Math.min(hPer, vPer);
  19. }
  20. clip._width = (clip._width)*percent;
  21. clip._height = (clip._height)*percent;
  22. }

Report this snippet  

You need to login to post a comment.