{"id":291,"date":"2009-05-21T16:16:13","date_gmt":"2009-05-21T23:16:13","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1413"},"modified":"2009-05-21T16:16:13","modified_gmt":"2009-05-21T23:16:13","slug":"bounds-3-ways","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=291","title":{"rendered":"Bounds 3 Ways"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n\/\/ make a complex poly and position it randomly\r\nvar poly:Sprite = Sprite(addChild(new Sprite()));\r\npoly.graphics.lineStyle(3, 0xFF0000);\r\npoly.graphics.beginFill(0x00FF00);\r\nfor (var i:int = 0; i&lt;10; i++) {\r\n\tpoly.graphics.lineTo(Math.random()*100 - 50, Math.random()*100 - 50);\r\n}\r\npoly.x=Math.random()*stage.stageWidth;\r\npoly.y=Math.random()*stage.stageHeight;\r\n\r\n\/\/ get bound information:\r\n\r\n\/\/ is in pixels (whole numbers)\r\ntrace(&quot;pixelBounds: &quot;, poly.transform.pixelBounds);\r\n\/\/ doesn&#039;t include stroke width\r\ntrace(&quot;getBounds: &quot;, poly.getBounds(this));\r\n\/\/ includes stroke width\r\ntrace(&quot;getRect: &quot;, poly.getRect(this));\r\n<\/pre>\n<p>Three different ways to get the boundaries of a DisplayObject.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ 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&lt;10; i++) { poly.graphics.lineTo(Math.random()*100 &#8211; 50, Math.random()*100 &#8211; 50); } poly.x=Math.random()*stage.stageWidth; poly.y=Math.random()*stage.stageHeight; \/\/ get bound information: \/\/ is in pixels (whole numbers) trace(&quot;pixelBounds: &quot;, poly.transform.pixelBounds); \/\/ doesn&#039;t include stroke width trace(&quot;getBounds: &quot;, poly.getBounds(this)); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[3,4],"class_list":["post-291","post","type-post","status-publish","format-standard","hentry","category-displayobject","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=291"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/291\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}