Posted By

trevorhartman on 06/19/09


Tagged

resize background scale as3


Versions (?)

Who likes this?

12 people have marked this snippet as a favorite

flashinit
dpollen
macKaminski
pauloc
Pingpongbal
quan
iamgowan
TrentSkunk
davidino1978
ssolen
kojok
adrianparr


smart background scaling


 / Published in: ActionScript 3
 

  1. // STEP 1
  2. // Create _contentWidth and _contentHeight as private vars to store the initial _content dimensions.
  3.  
  4. _contentWidth = _content.width;
  5. _contentHeight = _content.height;
  6.  
  7.  
  8. // STEP 2
  9. // In your resize handler, use the following code:
  10.  
  11. var scale:Number = 1;
  12. if ( _contentWidth < stage.stageWidth || _contentHeight < stage.stageHeight )
  13. {
  14. scale = Math.max( stage.stageHeight / _contentHeight, stage.stageWidth / _contentWidth );
  15. }
  16.  
  17.  
  18. // STEP 3
  19. // To apply the calculated scale, use:
  20.  
  21. _content.width = _contentWidth * scale;
  22. _content.height = _contentHeight * scale;

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: dpollen on July 2, 2009

This seems to have a problem with the width and height of masked content.

Any ideas how to work around this?

Posted By: trevorhartman on July 7, 2009

i've found that masks screw up the width and height properties. you could override public function get width():Number and height():Number inside the object you're scaling, or use separate properties to store the correct dimensions

You need to login to post a comment.