{"id":122,"date":"2010-05-19T10:59:45","date_gmt":"2010-05-19T09:59:45","guid":{"rendered":"http:\/\/www.aymericlamboley.fr\/blog\/?p=122"},"modified":"2010-05-19T11:03:01","modified_gmt":"2010-05-19T10:03:01","slug":"the-final-countdown","status":"publish","type":"post","link":"http:\/\/www.aymericlamboley.fr\/blog\/the-final-countdown\/","title":{"rendered":"The final Countdown"},"content":{"rendered":"<p>Hey there ! This is a little script to made a simple countdown on 12\/12\/2012 at 12:12:12. You know, the end of the world \ud83d\ude09<br \/>\n<a href=\"http:\/\/www.aymericlamboley.fr\/blog\/wp-content\/uploads\/2010\/05\/Countdown.swf\" rel=\"lightbox[flash 400 300]\"><strong>The result.<\/strong><\/a><\/p>\n<p>And the code :<\/p>\n<pre lang=\"actionscript3\" line=\"1\">package {\r\n\timport flash.display.Sprite;\r\n\timport flash.events.Event;\r\n\timport flash.text.TextField;\r\n\timport flash.text.TextFieldAutoSize;\r\n\timport flash.text.TextFormat;\r\n\r\n\t\/**\r\n\t * @author Aymeric\r\n\t *\/\r\n\tpublic class Countdown extends Sprite {\r\n\t\t\r\n\t\tprivate var target:Date;\r\n\t\tprivate var now:Date;\r\n\t\tprivate var currentTime:Number;\r\n\t\tprivate var targetTime:Number;\r\n\t\tprivate var time:TextField;\r\n\t\tprivate var format:TextFormat; \r\n\t\t\r\n\t\tpublic function Countdown() {\r\n\t\t\t\r\n\t\t\ttarget = new Date(2012, 11, 12, 12, 12, 12); \/\/ january = 0 -> december = 11\r\n\t\t\t\r\n\t\t\ttime = new TextField();\r\n\t\t\tformat = new TextFormat(\"Arial\", 30);\r\n\t\t\ttime.textColor = 0xFF0000;\r\n\t\t\ttime.x = stage.stageWidth\/2 - 100;\r\n\t\t\ttime.y = stage.stageHeight\/2 - 50;\r\n\t\t\ttime.embedFonts = true;\r\n\t\t\t\r\n\t\t\taddChild(time);\r\n\t\t\t\r\n\t\t\taddEventListener(Event.ENTER_FRAME, refresh);\r\n\t\t}\r\n\t\t\r\n\t\tprivate function refresh(e:Event):void {\r\n\t\t\t\r\n\t\t\tnow = new Date();\r\n\t\t\tcurrentTime = now.getTime();\r\n\t\t\ttargetTime = target.getTime();\r\n\t\t\t\r\n\t\t\tvar nbrSeconds:Number = (targetTime - currentTime)\/1000;\r\n\t\t\tvar seconds:Number = Math.floor(nbrSeconds%60);\r\n\t\t\tvar minutes:Number = Math.floor(nbrSeconds\/60%60);\r\n\t\t\tvar hours:Number = Math.floor(nbrSeconds\/3600%24);\r\n\t\t\tvar days:Number = Math.floor(nbrSeconds\/3600\/24);\r\n\t\t\t\r\n\t\t\tvar secondText:String;\r\n\t\t\tvar minuteText:String;\r\n\t\t\tvar hourText:String;\r\n\t\t\t\r\n\t\t\tif (seconds < 10) {\r\n\t\t\t\tsecondText = \"0\" + seconds;\r\n\t\t\t} else {\r\n\t\t\t\tsecondText = seconds.toString();\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif (minutes < 10) {\r\n\t\t\t\tminuteText = \"0\" + minutes;\r\n\t\t\t} else {\r\n\t\t\t\tminuteText = minutes.toString();\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif (hours < 10) {\r\n\t\t\t\thourText = \"0\" + hours;\r\n\t\t\t} else {\r\n\t\t\t\thourText = hours.toString();\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\ttime.text = days.toString() + \" : \" + hourText + \" : \" + minuteText + \" : \" + secondText;\r\n\t\t\ttime.autoSize = TextFieldAutoSize.LEFT;\r\n\t\t\ttime.setTextFormat(format);\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>I used an EnterFrame to refresh the countdown, but I have hesitated with a Timer which is called each seconds. I think the EnterFrame is better because the Timer depends of user's computer. If you can highlight me, do not hesitate !<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey there ! This is a little script to made a simple countdown on 12\/12\/2012 at 12:12:12. You know, the end of the world \ud83d\ude09 The result. And the code : package { import flash.display.Sprite; import flash.events.Event; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; \/** * @author Aymeric *\/ public class Countdown extends Sprite { private &hellip; <a href=\"http:\/\/www.aymericlamboley.fr\/blog\/the-final-countdown\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">The final Countdown<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[4],"tags":[],"_links":{"self":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/122"}],"collection":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/comments?post=122"}],"version-history":[{"count":2,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/122\/revisions"}],"predecessor-version":[{"id":124,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/122\/revisions\/124"}],"wp:attachment":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/media?parent=122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/categories?post=122"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/tags?post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}