AS3 getVisibleBounds


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

All credit for this goes to Zach Foley (aka Plastic Sturgeon)


Copy this code and paste it in your HTML
  1. package util
  2. {
  3. import flash.display.DisplayObject;
  4. import flash.display.BitmapData;
  5. import flash.geom.Rectangle;
  6. import flash.geom.Matrix;
  7. public function getVisibleBounds(source:DisplayObject):Rectangle
  8. {
  9. // Updated 11-18-2010;
  10. // Thanks to Mark in the comments for this addition;
  11. var matrix:Matrix = new Matrix()
  12. matrix.tx = -source.getBounds(null).x;
  13. matrix.ty = -source.getBounds(null).y;
  14.  
  15. var data:BitmapData = new BitmapData(source.width, source.height, true, 0x00000000);
  16. data.draw(source, matrix);
  17. var bounds : Rectangle = data.getColorBoundsRect(0xFFFFFFFF, 0x000000, false);
  18. data.dispose();
  19. return bounds;
  20. }
  21. }

URL: http://plasticsturgeon.com/2010/09/as3-get-visible-bounds-of-transparent-display-object/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.