{"id":188,"date":"2009-02-14T15:01:46","date_gmt":"2009-02-14T22:01:46","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=783"},"modified":"2009-02-14T15:01:46","modified_gmt":"2009-02-14T22:01:46","slug":"circles-cacheasbitmap","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=188","title":{"rendered":"Circles &#038; cacheAsBitmap"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n&#x5B;SWF(width=600,height=400,backgroundColor=0x000000,frameRate=30)]\r\nvar mcs:Vector.&lt;MovieClip&gt; = new Vector.&lt;MovieClip&gt;();\r\nvar num:int = 2000;\r\nfor (var i:int = 0; i&lt;num; i++){\r\n\tvar s:MovieClip = new MovieClip();\r\n\ts.graphics.lineStyle(0,0xFFFFFF);\r\n\ts.graphics.drawCircle(0,0, Math.random()*30 + 3);\r\n\ts.x = Math.random()*stage.stageWidth;\r\n\ts.y = Math.random()*stage.stageHeight;\r\n       \/\/ comment out to kill your cpu\r\n\ts.cacheAsBitmap = true;\r\n\taddChild(s);\r\n\ts.vx  = Math.random() * 2 - 1;\r\n\ts.vy  = Math.random() * 2 - 1;\r\n    mcs.push(s);\r\n}\r\naddEventListener(Event.ENTER_FRAME, onCenter);\r\nfunction onCenter(evt:Event):void{\r\n\tfor (var i:int = 0; i&lt;num; i++){\r\n\t\tmcs&#x5B;i].x += mcs&#x5B;i].vx;\r\n\t\tmcs&#x5B;i].y += mcs&#x5B;i].vy;\r\n\t}\r\n}\r\n<\/pre>\n<p>This was created in response to a question about the real speed gain of cacheAsBitmap. Just comment out the cacheAsBitmap line to see the difference.<\/p>\n<p>Despite it&#8217;s extreme simplicity, this is actually a rather fun file to play with, change some of the graphics class method calls around and see what happens.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x5B;SWF(width=600,height=400,backgroundColor=0x000000,frameRate=30)] var mcs:Vector.&lt;MovieClip&gt; = new Vector.&lt;MovieClip&gt;(); var num:int = 2000; for (var i:int = 0; i&lt;num; i++){ var s:MovieClip = new MovieClip(); s.graphics.lineStyle(0,0xFFFFFF); s.graphics.drawCircle(0,0, Math.random()*30 + 3); s.x = Math.random()*stage.stageWidth; s.y = Math.random()*stage.stageHeight; \/\/ comment out to kill your cpu s.cacheAsBitmap = true; addChild(s); s.vx = Math.random() * 2 &#8211; 1; s.vy = Math.random() * [&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,33],"tags":[3,4],"class_list":["post-188","post","type-post","status-publish","format-standard","hentry","category-displayobject","category-graphics","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/188","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=188"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/188\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}