Bounds 3 Ways

// 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.

1 comment

Leave a Reply

Your email address will not be published. Required fields are marked *