Return to Snippet

Revision: 55741
at February 20, 2012 21:09 by adrianparr


Initial Code
package util
{
   import flash.display.DisplayObject;
   import flash.display.BitmapData;
   import flash.geom.Rectangle;
   import flash.geom.Matrix;
   public function getVisibleBounds(source:DisplayObject):Rectangle
   {
       // Updated 11-18-2010;
       // Thanks to Mark in the comments for this addition;
       var matrix:Matrix = new Matrix()
       matrix.tx = -source.getBounds(null).x;
       matrix.ty = -source.getBounds(null).y;
 
       var data:BitmapData = new BitmapData(source.width, source.height, true, 0x00000000);
       data.draw(source, matrix);
       var bounds : Rectangle = data.getColorBoundsRect(0xFFFFFFFF, 0x000000, false);
       data.dispose();
       return bounds;
   }
}

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

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

Initial Title
AS3 getVisibleBounds

Initial Tags


Initial Language
ActionScript 3