/ Published in: ActionScript 3
All credit for this goes to Zach Foley (aka Plastic Sturgeon)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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; } }
URL: http://plasticsturgeon.com/2010/09/as3-get-visible-bounds-of-transparent-display-object/