Posted By

arpo on 01/27/10


Tagged


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

Demian
adrianparr
davidino1978
bradvanspriellgmailcom
thastyle
albertomori


Scale by ratio


 / Published in: ActionScript 3
 

Scale an object with fixed aspect ratio to fit in a specific area.

  1. function scaleByRatio(obj:DisplayObject, maxWidth:Number, maxHeight:Number):void {
  2. if (obj.width > obj.height) {
  3. obj.height = (maxWidth * obj.height) / obj.width
  4. obj.width = maxWidth;
  5. }else if (obj.height > obj.width) {
  6. obj.width = (maxHeight * obj.width) / obj.height
  7. obj.height = maxHeight;
  8. }else {
  9. obj.width = maxWidth;
  10. obj.height = maxHeight;
  11. }
  12. }

Report this snippet  

You need to login to post a comment.