{"id":101,"date":"2006-11-27T03:13:29","date_gmt":"2006-11-27T01:13:29","guid":{"rendered":"http:\/\/www.nivas.hr\/blog\/2006\/11\/27\/as3-kitchen-timer-and-enter_frame\/"},"modified":"2008-11-11T12:59:26","modified_gmt":"2008-11-11T10:59:26","slug":"as3-kitchen-timer-and-enter_frame","status":"publish","type":"post","link":"https:\/\/www.nivas.hr\/blog\/2006\/11\/27\/as3-kitchen-timer-and-enter_frame\/","title":{"rendered":"AS3 Kitchen &#8211; Timer and ENTER_FRAME"},"content":{"rendered":"<p>There is no mc.onEnterFrame in AS3 anymore, but there is something so much better &#8211; ENTER_FRAME event! Since pretty much everything in AS3 is event based, that makes perfect sense. There is also a new event based Timer class which replaces darn setInterval. The guru of ActionScripted motion &#8211; Keith Peters wrote a great <a target=\"_blank\" href=\"http:\/\/www.bit-101.com\/blog\/?p=910\">post<\/a> on subject of common misconceptions in usage.<br \/>\n<!--more--><\/p>\n<p><strong>AS3 EnterFrame event:<\/strong><br \/>\n[ftf w=&#8221;490&#8243; h=&#8221;400&#8243;]<br \/>\npackage {<br \/>\nimport flash.display.*;<br \/>\nimport flash.events.*;<\/p>\n<p>public class TestEnterFrame extends Sprite<br \/>\n{<br \/>\npublic function TestEnterFrame()<br \/>\n{<br \/>\naddEventListener(Event.ENTER_FRAME, onEnterFrame);<br \/>\n}<\/p>\n<p>private function onEnterFrame(ev:Event):void<br \/>\n{<br \/>\ntrace(&#8220;onenterframe:&#8221;+ev);<br \/>\n}<br \/>\n}<\/p>\n<p>}<br \/>\n[\/ftf]<br \/>\n<strong>AS3 Timer class test: <\/strong><br \/>\n[ftf w=&#8221;490&#8243; h=&#8221;400&#8243;]<br \/>\npackage {<br \/>\nimport flash.display.Sprite;<br \/>\nimport flash.events.TimerEvent;<br \/>\nimport flash.utils.getTimer;<br \/>\nimport flash.utils.Timer;<br \/>\npublic class Tests extends Sprite<br \/>\n{<br \/>\nprivate var start:Number;<br \/>\npublic function Tests()<br \/>\n{<br \/>\nvar timer:Timer = new Timer(1000);<br \/>\ntimer.addEventListener(TimerEvent.TIMER, onTimer);<br \/>\nstart = getTimer();<br \/>\ntimer.start();<br \/>\n}<br \/>\nprivate function onTimer(event:TimerEvent):void<br \/>\n{<br \/>\ntrace(getTimer() &#8211; start);<br \/>\nstart = getTimer();<br \/>\nfor(var i:uint = 0; i <1000000; i++)\n{\nvar j:Number = Math.random();\n}\ntrace(\"elapsed time in function: \" + (getTimer() - start));\n}\n}\n}\n[\/ftf]\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is no mc.onEnterFrame in AS3 anymore, but there is something so much better &#8211; ENTER_FRAME event! Since pretty much everything in AS3 is event based, that makes perfect sense. There is also a new event based Timer class which replaces darn setInterval. The guru of ActionScripted motion &#8211; Keith Peters wrote a great post&#8230;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,2],"tags":[],"_links":{"self":[{"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/posts\/101"}],"collection":[{"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/comments?post=101"}],"version-history":[{"count":3,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/posts\/101\/revisions"}],"predecessor-version":[{"id":700,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/posts\/101\/revisions\/700"}],"wp:attachment":[{"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/media?parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/categories?post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nivas.hr\/blog\/wp-json\/wp\/v2\/tags?post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}