// make a complex poly and position it randomly
var poly:Sprite = Sprite(addChild(new Sprite()));
poly.graphics.lineStyle(3, 0xFF0000);
poly.graphics.beginFill(0x00FF00);
for (var i:int = 0; i<10; i++) {
poly.graphics.lineTo(Math.random()*100 - 50, Math.random()*100 - 50);
}
poly.x=Math.random()*stage.stageWidth;
poly.y=Math.random()*stage.stageHeight;
// get bound information:
// is in pixels (whole numbers)
trace("pixelBounds: ", poly.transform.pixelBounds);
// doesn't include stroke width
trace("getBounds: ", poly.getBounds(this));
// includes stroke width
trace("getRect: ", poly.getRect(this));
Three different ways to get the boundaries of a DisplayObject.
These are all fine methods to get the bounds, but it’s the split case if you’ve got to consider transformations, e.g. visible boundaries of a DisplayObject on stage.
Thus I call to vote for this functionality at Adobe’s Bug System, FP-741.