Skip to content

Instantly share code, notes, and snippets.

@k0t0vich
Created March 6, 2015 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k0t0vich/8a518897541bd3174713 to your computer and use it in GitHub Desktop.
Save k0t0vich/8a518897541bd3174713 to your computer and use it in GitHub Desktop.
getVisibleBounds
package arp.utils {
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.geom.Matrix;
import flash.geom.Rectangle;
public function getVisibleBounds(source:DisplayObject, padding:int = 0):Rectangle {
var matrix:Matrix = new Matrix()
matrix.tx = -source.getBounds(null).x + padding;
matrix.ty = -source.getBounds(null).y + padding;
var data:BitmapData = new BitmapData(source.width + padding *2, source.height + padding *2, true, 0x00000000);
data.draw(source, matrix);
var bounds : Rectangle = data.getColorBoundsRect(0xFFFFFFFF, 0x000000, false);
bounds.offset(-matrix.tx, -matrix.ty);
data.dispose();
return bounds;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment