smart background scaling


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



Copy this code and paste it in your HTML
  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

You need to login to post a comment.