{"id":91,"date":"2008-11-12T00:00:24","date_gmt":"2008-11-12T07:00:24","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=105"},"modified":"2008-11-12T00:00:24","modified_gmt":"2008-11-12T07:00:24","slug":"2d-z-sort","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=91","title":{"rendered":"2D Z-Sort"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar shapes:Array = new Array();\r\n\r\nfor (var i:int = 0; i&lt;300; i++){\r\n\tvar s:Shape = new Shape();\r\n\ts.x = Math.random()* stage.stageWidth;\r\n\ts.y = Math.random()* stage.stageHeight;\r\n\ts.graphics.lineStyle(0,0x000000);\r\n\ts.graphics.beginFill(0xCCCCCC);\r\n\ts.graphics.drawCircle(0,0, Math.random()*s.y \/ 5);\r\n\tshapes.push(s);\r\n}\r\n\r\n\/\/ comment this out to remove sorting\r\nshapes.sortOn(&quot;width&quot;, Array.NUMERIC);\r\n\r\nfor (i = 0; i&lt;shapes.length; i++){\r\n\taddChild(shapes&#x5B;i]);\r\n}\r\n<\/pre>\n<p>This uses Array.sortOn() to do some basic z-sorting based on the width property of some circle shapes. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>var shapes:Array = new Array(); for (var i:int = 0; i&lt;300; i++){ var s:Shape = new Shape(); s.x = Math.random()* stage.stageWidth; s.y = Math.random()* stage.stageHeight; s.graphics.lineStyle(0,0&#215;000000); s.graphics.beginFill(0xCCCCCC); s.graphics.drawCircle(0,0, Math.random()*s.y \/ 5); shapes.push(s); } \/\/ comment this out to remove sorting shapes.sortOn(&quot;width&quot;, Array.NUMERIC); for (i = 0; i&lt;shapes.length; i++){ addChild(shapes&#x5B;i]); } This uses Array.sortOn() to do [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,47],"tags":[48,49],"class_list":["post-91","post","type-post","status-publish","format-standard","hentry","category-arrays","category-sorton","tag-sorting","tag-z-sorting"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/91","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=91"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/91\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=91"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=91"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=91"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}