Created
March 6, 2015 13:25
-
-
Save k0t0vich/8a518897541bd3174713 to your computer and use it in GitHub Desktop.
getVisibleBounds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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