{"id":1238,"date":"2011-03-03T23:20:51","date_gmt":"2011-03-04T06:20:51","guid":{"rendered":"http:\/\/www.nathalielawhead.com\/candybox\/?p=1238"},"modified":"2014-03-18T23:48:04","modified_gmt":"2014-03-19T06:48:04","slug":"flash-actionscript-3-countdown-timer-set-to-servertime-php-the-countdown-you-cant-cheat","status":"publish","type":"post","link":"http:\/\/www.nathalielawhead.com\/candybox\/flash-actionscript-3-countdown-timer-set-to-servertime-php-the-countdown-you-cant-cheat","title":{"rendered":"Flash Actionscript 3 Countdown Timer Set To Servertime (PHP) &#8211; The Countdown You Can&#8217;t Cheat"},"content":{"rendered":"<p>I&#8217;ve been itching to do one for a long time since I keep being asked to do countdown timers&#8230; Then there&#8217;s always that pesky deadline that keeps me from actually not cutting corners and doin&#8217; it fo&#8217; realz. So dundid I didit! A countdown timer set to server time via PHP!<br \/>\n(&#8230;You know, it should work, but I didn&#8217;t test it through n&#8217; through, just threw the servertime integration together this evening :S ).<\/p>\n<p>Source files <a href=\"http:\/\/nathalielawhead.com\/sourcefiles\/Countdown_Timer_To_Servertime\" target=\"_blank\">up for grabs <strong>HERE!<\/strong> <\/a><\/p>\n<p>The deal is if you do a countdown in Flash, the Flash Date object is set to the user&#8217;s system clock. If you decide to set your system time to&#8230; lets say&#8230; the year 2090 and beyond (or whatever) the countdown (of course) detects that the target date is so totally over.<br \/>\nMany clients think they&#8217;re sneaky and try to break your shit that way and then think that users will do the same.<br \/>\nDeal is no one cares, or really cares to try that, and if they do they know why the timer reads 00:00:00, BUT there are occasions where you&#8217;ll just want to do that (like in the case of ARG&#8217;s&#8230; or when the unexpected is expectable!)&#8230;<br \/>\nIt&#8217;s Flash. There are always occasions where you&#8217;ll want to make an exception to the rule and do some weird experimental wizardry.<\/p>\n<p>In AS you have two instances of the Date Object you need. One is the current date and one is the target date.<br \/>\nThe current date is what you need to pass the server time too. From then on the rest is just classic countdown timer stuff&#8230; calculate target &#8211; current time left, break it down to seconds, minutes, hours, days, turn that to strings, blah, blah, etc&#8230;<br \/>\nI&#8217;m not the greatest PHP-ist in the world. In fact I get by. So this was (don&#8217;t laugh) a bit hard for me because it&#8217;s simple. Too simple!<br \/>\nLike any amateur, I tend to over complicate things when I don&#8217;t know what I&#8217;m doing&#8230; so, in trying to get the PHP date output to match that which Flash accepts, I was feeding it every combination of formats and date constants (D, d M Y H:i:s etc) under the sun.<br \/>\nTurns out you just need &#8220;r&#8221;.<br \/>\nLike so:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #557799\">&lt;?php<\/span>\r\n<span style=\"color: #996633\">$date<\/span> <span style=\"color: #333333\">=<\/span> <span style=\"color: #007020\">date<\/span>(<span style=\"background-color: #fff0f0\">&quot;r&quot;<\/span>, <span style=\"color: #007020\">time<\/span>());\r\n<span style=\"color: #008800; font-weight: bold\">echo<\/span> <span style=\"color: #996633\">$date<\/span>;\r\n<span style=\"color: #557799\">?&gt;<\/span>\r\n<\/pre>\n<\/div>\n<p>Update the .as file with the URL to your .php file.<\/p>\n<p>Load that into Flash (via URLRequest), make sure it&#8217;s a string, and pass that string (in this case var loadedDateString:String) to the Date object via Date.parse.<br \/>\nLike so:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #008800; font-weight: bold\">var<\/span> currentDate:<span style=\"color: #333399; font-weight: bold\">Date<\/span> <span style=\"color: #333333\">=<\/span> <span style=\"color: #008800; font-weight: bold\">new<\/span> <span style=\"color: #333399; font-weight: bold\">Date<\/span><span style=\"color: #333333\">(<\/span>Date<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">parse<\/span><span style=\"color: #333333\">(<\/span>loadedDateString<span style=\"color: #333333\">));<\/span>\r\n<\/pre>\n<\/div>\n<p>That&#8217;s basically it.<\/p>\n<p>Here&#8217;s a working example:<\/p>\n<p><a href=\"http:\/\/nathalielawhead.com\/sourcefiles\/Countdown_Timer_To_Servertime\/counter_cs4.swf\" target=\"_blank\"><img decoding=\"async\" src=\"http:\/\/nathalielawhead.com\/noodles\/countdown.jpg\" alt=\"Flash Countdown Timer From Server Time PHP\" \/><\/a><br \/>\n<em>&#8211;<a href=\"http:\/\/nathalielawhead.com\/noodles\/_counter_cs4.html\" target=\"_blank\">Click to view<\/a>.<\/em><\/p>\n<p>It&#8217;s a Counter.as class (view the <a href=\"http:\/\/nathalielawhead.com\/sourcefiles\/Countdown_Timer_To_Servertime\/Counter.as\" target=\"_blank\">AS HERE &#8211; right click + save as<\/a>).<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #008800; font-weight: bold\">package<\/span> <span style=\"color: #333333\">{<\/span>\r\n\r\n\t<span style=\"color: #008800; font-weight: bold\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold\">flash.display.MovieClip<\/span><span style=\"color: #333333\">;<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold\">flash.events.Event<\/span><span style=\"color: #333333\">;<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold\">flash.events.TimerEvent<\/span><span style=\"color: #333333\">;<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold\">flash.utils.Timer<\/span><span style=\"color: #333333\">;<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold\">flash.events.TextEvent<\/span><span style=\"color: #333333\">;<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold\">flash.net.URLLoader<\/span><span style=\"color: #333333\">;<\/span>\r\n\t<span style=\"color: #008800; font-weight: bold\">import<\/span> <span style=\"color: #0e84b5; font-weight: bold\">flash.net.URLRequest<\/span><span style=\"color: #333333\">;<\/span>\r\n\r\n\t<span style=\"color: #008800; font-weight: bold\">public<\/span> <span style=\"color: #008800; font-weight: bold\">class<\/span> Counter <span style=\"color: #008800; font-weight: bold\">extends<\/span> MovieClip <span style=\"color: #333333\">{<\/span>\r\n\r\n\t\t<span style=\"color: #888888\">\/\/Strings (Current count)<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold\">private<\/span> <span style=\"color: #008800; font-weight: bold\">var<\/span> sec:<span style=\"color: #333399; font-weight: bold\">String<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold\">private<\/span> <span style=\"color: #008800; font-weight: bold\">var<\/span> min:<span style=\"color: #333399; font-weight: bold\">String<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold\">private<\/span> <span style=\"color: #008800; font-weight: bold\">var<\/span> hrs:<span style=\"color: #333399; font-weight: bold\">String<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold\">private<\/span> <span style=\"color: #008800; font-weight: bold\">var<\/span> d:<span style=\"color: #333399; font-weight: bold\">String<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t<span style=\"color: #888888\">\/\/ (Previous count to check flip animation against)<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold\">private<\/span> <span style=\"color: #008800; font-weight: bold\">var<\/span> old_sec:<span style=\"color: #333399; font-weight: bold\">String<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold\">private<\/span> <span style=\"color: #008800; font-weight: bold\">var<\/span> old_min:<span style=\"color: #333399; font-weight: bold\">String<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold\">private<\/span> <span style=\"color: #008800; font-weight: bold\">var<\/span> old_hrs:<span style=\"color: #333399; font-weight: bold\">String<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold\">private<\/span> <span style=\"color: #008800; font-weight: bold\">var<\/span> old_d:<span style=\"color: #333399; font-weight: bold\">String<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t<span style=\"color: #888888\">\/\/for holding the php servertime<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold\">private<\/span> <span style=\"color: #008800; font-weight: bold\">var<\/span> loadedDateString:<span style=\"color: #333399; font-weight: bold\">String<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t<span style=\"color: #888888\">\/\/<\/span>\r\n\t\t<span style=\"color: #008800; font-weight: bold\">public<\/span> <span style=\"color: #008800; font-weight: bold\">function <\/span><span style=\"color: #0066BB; font-weight: bold\">Counter<\/span><span style=\"color: #333333\">(<\/span>year<span style=\"color: #333333\">:<\/span><span style=\"color: #333399; font-weight: bold\">Number<\/span><span style=\"color: #333333\">,<\/span> month<span style=\"color: #333333\">:<\/span><span style=\"color: #333399; font-weight: bold\">Number<\/span><span style=\"color: #333333\">,<\/span> date<span style=\"color: #333333\">:<\/span><span style=\"color: #333399; font-weight: bold\">Number<\/span><span style=\"color: #333333\">):<\/span><span style=\"color: #333399; font-weight: bold\">void<\/span> <span style=\"color: #333333\">{<\/span>\r\n\t\t\t<span style=\"color: #888888\">\/\/url loader &amp; timer<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold\">var<\/span> ldr_servertime:<span style=\"color: #333399; font-weight: bold\">URLLoader<\/span> <span style=\"color: #333333\">=<\/span> <span style=\"color: #008800; font-weight: bold\">new<\/span> <span style=\"color: #333399; font-weight: bold\">URLLoader<\/span><span style=\"color: #333333\">();<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold\">var<\/span> timer:<span style=\"color: #333399; font-weight: bold\">Timer<\/span><span style=\"color: #333333\">=<\/span><span style=\"color: #008800; font-weight: bold\">new<\/span> <span style=\"color: #333399; font-weight: bold\">Timer<\/span><span style=\"color: #333333\">(<\/span><span style=\"color: #0000DD; font-weight: bold\">1000<\/span><span style=\"color: #333333\">);<\/span>\r\n\t\t\ttimer<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">addEventListener<\/span><span style=\"color: #333333\">(<\/span>TimerEvent<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">TIMER<\/span><span style=\"color: #333333\">,<\/span> count<span style=\"color: #333333\">);<\/span>\r\n\t\t\ttimer<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">start<\/span><span style=\"color: #333333\">();<\/span>\r\n\t\t\t<span style=\"color: #888888\">\/\/Date object - !!!Months are counted from 0!!!<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold\">var<\/span> targetDate:<span style=\"color: #333399; font-weight: bold\">Date<\/span><span style=\"color: #333333\">=<\/span><span style=\"color: #008800; font-weight: bold\">new<\/span> <span style=\"color: #333399; font-weight: bold\">Date<\/span><span style=\"color: #333333\">(<\/span>year<span style=\"color: #333333\">,<\/span>month<span style=\"color: #333333\">,<\/span>date<span style=\"color: #333333\">);<\/span>\r\n\t\t\t<span style=\"color: #888888\">\/\/count timer - magic happens here<\/span>\r\n\t\t\t<span style=\"color: #008800; font-weight: bold\">function <\/span><span style=\"color: #0066BB; font-weight: bold\">count<\/span><span style=\"color: #333333\">(<\/span>e<span style=\"color: #333333\">:<\/span><span style=\"color: #333399; font-weight: bold\">TimerEvent<\/span><span style=\"color: #333333\">):<\/span><span style=\"color: #333399; font-weight: bold\">void<\/span> <span style=\"color: #333333\">{<\/span>\r\n\t\t\t\t<span style=\"color: #888888\">\/\/load php<\/span>\r\n\t\t\t\tldr_servertime<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">load<\/span><span style=\"color: #333333\">(<\/span><span style=\"color: #008800; font-weight: bold\">new<\/span> <span style=\"color: #333399; font-weight: bold\">URLRequest<\/span><span style=\"color: #333333\">(<\/span><span style=\"background-color: #fff0f0\">&quot;http:\/\/PATHTOFILE.COM\/servertime.php&quot;<\/span><span style=\"color: #333333\">));<\/span>\r\n\t\t\t\tldr_servertime<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">addEventListener<\/span><span style=\"color: #333333\">(<\/span>Event<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">COMPLETE<\/span><span style=\"color: #333333\">,<\/span> onLoaded<span style=\"color: #333333\">);<\/span>\r\n\t\t\t\t<span style=\"color: #888888\">\/\/load the php servertime and pass it to loadedDateString for later parsing<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">function <\/span><span style=\"color: #0066BB; font-weight: bold\">onLoaded<\/span><span style=\"color: #333333\">(<\/span>evt<span style=\"color: #333333\">:<\/span><span style=\"color: #333399; font-weight: bold\">Event<\/span><span style=\"color: #333333\">)<\/span> <span style=\"color: #333333\">{<\/span>\r\n\t\t\t\t\tloadedDateString<span style=\"color: #333333\">=<\/span>ldr_servertime<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">data<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t\t\t<span style=\"color: #333333\">}<\/span>\r\n\t\t\t\t<span style=\"color: #888888\">\/\/current date feed it loadedDateString and parse it... like a boss<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">var<\/span> currentDate:<span style=\"color: #333399; font-weight: bold\">Date<\/span><span style=\"color: #333333\">=<\/span><span style=\"color: #008800; font-weight: bold\">new<\/span> <span style=\"color: #333399; font-weight: bold\">Date<\/span><span style=\"color: #333333\">(<\/span>Date<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">parse<\/span><span style=\"color: #333333\">(<\/span>loadedDateString<span style=\"color: #333333\">));<\/span>\r\n\t\t\t\t<span style=\"color: #888888\">\/\/calculate<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">var<\/span> timeLeft:<span style=\"color: #333399; font-weight: bold\">Number<\/span><span style=\"color: #333333\">=<\/span>targetDate<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">getTime<\/span><span style=\"color: #333333\">()-<\/span>currentDate<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">getTime<\/span><span style=\"color: #333333\">();<\/span>\r\n\t\t\t\t<span style=\"color: #888888\">\/\/remaining time to seconds, minutes, hours and days<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">var<\/span> seconds:<span style=\"color: #333399; font-weight: bold\">Number<\/span><span style=\"color: #333333\">=<\/span>Math<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">floor<\/span><span style=\"color: #333333\">(<\/span>timeLeft<span style=\"color: #333333\">\/<\/span><span style=\"color: #0000DD; font-weight: bold\">1000<\/span><span style=\"color: #333333\">);<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">var<\/span> minutes:<span style=\"color: #333399; font-weight: bold\">Number<\/span><span style=\"color: #333333\">=<\/span>Math<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">floor<\/span><span style=\"color: #333333\">(<\/span>seconds<span style=\"color: #333333\">\/<\/span><span style=\"color: #0000DD; font-weight: bold\">60<\/span><span style=\"color: #333333\">);<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">var<\/span> hours:<span style=\"color: #333399; font-weight: bold\">Number<\/span><span style=\"color: #333333\">=<\/span>Math<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">floor<\/span><span style=\"color: #333333\">(<\/span>minutes<span style=\"color: #333333\">\/<\/span><span style=\"color: #0000DD; font-weight: bold\">60<\/span><span style=\"color: #333333\">);<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">var<\/span> days:<span style=\"color: #333399; font-weight: bold\">Number<\/span><span style=\"color: #333333\">=<\/span>Math<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">floor<\/span><span style=\"color: #333333\">(<\/span>hours<span style=\"color: #333333\">\/<\/span><span style=\"color: #0000DD; font-weight: bold\">24<\/span><span style=\"color: #333333\">);<\/span>\r\n\r\n\t\t\t\tseconds<span style=\"color: #333333\">%=<\/span><span style=\"color: #0000DD; font-weight: bold\">60<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t\t\tminutes<span style=\"color: #333333\">%=<\/span><span style=\"color: #0000DD; font-weight: bold\">60<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t\t\thours<span style=\"color: #333333\">%=<\/span><span style=\"color: #0000DD; font-weight: bold\">24<\/span><span style=\"color: #333333\">;<\/span>\r\n\r\n\t\t\t\t<span style=\"color: #888888\">\/\/numbers to strings <\/span>\r\n\t\t\t\tsec<span style=\"color: #333333\">=<\/span>seconds<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">toString<\/span><span style=\"color: #333333\">();<\/span>\r\n\t\t\t\tmin<span style=\"color: #333333\">=<\/span>minutes<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">toString<\/span><span style=\"color: #333333\">();<\/span>\r\n\t\t\t\thrs<span style=\"color: #333333\">=<\/span>hours<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">toString<\/span><span style=\"color: #333333\">();<\/span>\r\n\t\t\t\td<span style=\"color: #333333\">=<\/span>days<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">toString<\/span><span style=\"color: #333333\">();<\/span>\r\n\r\n\t\t\t\t<span style=\"color: #888888\">\/\/if single digit &quot;0&quot; infront<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">if<\/span> <span style=\"color: #333333\">(<\/span>sec<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">length<\/span><span style=\"color: #333333\">&amp;<\/span>lt<span style=\"color: #333333\">;<\/span><span style=\"color: #0000DD; font-weight: bold\">2<\/span><span style=\"color: #333333\">)<\/span> <span style=\"color: #333333\">{<\/span>\r\n\t\t\t\t\tsec<span style=\"color: #333333\">=<\/span><span style=\"background-color: #fff0f0\">&quot;0&quot;<\/span><span style=\"color: #333333\">+<\/span>sec<span style=\"color: #333333\">;<\/span>\r\n\t\t\t\t<span style=\"color: #333333\">}<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">if<\/span> <span style=\"color: #333333\">(<\/span>min<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">length<\/span><span style=\"color: #333333\">&amp;<\/span>lt<span style=\"color: #333333\">;<\/span><span style=\"color: #0000DD; font-weight: bold\">2<\/span><span style=\"color: #333333\">)<\/span> <span style=\"color: #333333\">{<\/span>\r\n\t\t\t\t\tmin<span style=\"color: #333333\">=<\/span><span style=\"background-color: #fff0f0\">&quot;0&quot;<\/span><span style=\"color: #333333\">+<\/span>min<span style=\"color: #333333\">;<\/span>\r\n\t\t\t\t<span style=\"color: #333333\">}<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">if<\/span> <span style=\"color: #333333\">(<\/span>hrs<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">length<\/span><span style=\"color: #333333\">&amp;<\/span>lt<span style=\"color: #333333\">;<\/span><span style=\"color: #0000DD; font-weight: bold\">2<\/span><span style=\"color: #333333\">)<\/span> <span style=\"color: #333333\">{<\/span>\r\n\t\t\t\t\thrs<span style=\"color: #333333\">=<\/span><span style=\"background-color: #fff0f0\">&quot;0&quot;<\/span><span style=\"color: #333333\">+<\/span>hrs<span style=\"color: #333333\">;<\/span>\r\n\t\t\t\t<span style=\"color: #333333\">}<\/span>\r\n\r\n\t\t\t\t<span style=\"color: #888888\">\/\/SET OLD\/NEW VALUES FOR FLIP ANIMATIONS<\/span>\r\n\t\t\t\told_d<span style=\"color: #333333\">=<\/span>txt_day<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">text<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t\t\told_hrs<span style=\"color: #333333\">=<\/span>txt_hour<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">text<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t\t\told_min<span style=\"color: #333333\">=<\/span>txt_min<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">text<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t\t\told_sec<span style=\"color: #333333\">=<\/span>txt_sec<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">text<\/span><span style=\"color: #333333\">;<\/span>\r\n\r\n\t\t\t\t<span style=\"color: #888888\">\/\/SET TEXT;<\/span>\r\n\t\t\t\ttxt_day<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">text<\/span><span style=\"color: #333333\">=<\/span>d<span style=\"color: #333333\">;<\/span>\r\n\t\t\t\ttxt_hour<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">text<\/span><span style=\"color: #333333\">=<\/span>hrs<span style=\"color: #333333\">;<\/span>\r\n\t\t\t\ttxt_min<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">text<\/span><span style=\"color: #333333\">=<\/span>min<span style=\"color: #333333\">;<\/span>\r\n\t\t\t\ttxt_sec<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">text<\/span><span style=\"color: #333333\">=<\/span>sec<span style=\"color: #333333\">;<\/span>\r\n\r\n\t\t\t\t<span style=\"color: #888888\">\/\/flip animation<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">if<\/span> <span style=\"color: #333333\">(<\/span>old_sec<span style=\"color: #333333\">!=<\/span>sec<span style=\"color: #333333\">)<\/span> <span style=\"color: #333333\">{<\/span>\r\n\t\t\t\t\tmc_ov_sec<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">gotoAndPlay<\/span><span style=\"color: #333333\">(<\/span><span style=\"color: #0000DD; font-weight: bold\">1<\/span><span style=\"color: #333333\">);<\/span>\r\n\t\t\t\t<span style=\"color: #333333\">}<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">if<\/span> <span style=\"color: #333333\">(<\/span>old_min<span style=\"color: #333333\">!=<\/span>min<span style=\"color: #333333\">)<\/span> <span style=\"color: #333333\">{<\/span>\r\n\t\t\t\t\tmc_ov_min<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">gotoAndPlay<\/span><span style=\"color: #333333\">(<\/span><span style=\"color: #0000DD; font-weight: bold\">1<\/span><span style=\"color: #333333\">);<\/span>\r\n\t\t\t\t<span style=\"color: #333333\">}<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">if<\/span> <span style=\"color: #333333\">(<\/span>old_hrs<span style=\"color: #333333\">!=<\/span>hrs<span style=\"color: #333333\">)<\/span> <span style=\"color: #333333\">{<\/span>\r\n\t\t\t\t\tmc_ov_hrs<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">gotoAndPlay<\/span><span style=\"color: #333333\">(<\/span><span style=\"color: #0000DD; font-weight: bold\">1<\/span><span style=\"color: #333333\">);<\/span>\r\n\t\t\t\t<span style=\"color: #333333\">}<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">if<\/span> <span style=\"color: #333333\">(<\/span>old_min<span style=\"color: #333333\">!=<\/span>min<span style=\"color: #333333\">)<\/span> <span style=\"color: #333333\">{<\/span>\r\n\t\t\t\t\tmc_ov_hrs<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">gotoAndPlay<\/span><span style=\"color: #333333\">(<\/span><span style=\"color: #0000DD; font-weight: bold\">1<\/span><span style=\"color: #333333\">);<\/span>\r\n\t\t\t\t<span style=\"color: #333333\">}<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">if<\/span> <span style=\"color: #333333\">(<\/span>old_d<span style=\"color: #333333\">!=<\/span>d<span style=\"color: #333333\">)<\/span> <span style=\"color: #333333\">{<\/span>\r\n\t\t\t\t\tmc_ov_d<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">gotoAndPlay<\/span><span style=\"color: #333333\">(<\/span><span style=\"color: #0000DD; font-weight: bold\">1<\/span><span style=\"color: #333333\">);<\/span>\r\n\t\t\t\t<span style=\"color: #333333\">}<\/span>\r\n\r\n\t\t\t\t<span style=\"color: #888888\">\/\/IS OVER?<\/span>\r\n\t\t\t\t<span style=\"color: #888888\">\/\/check if current date has passed target date so it doen&#39;st keep counting past the due date<\/span>\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">if<\/span> <span style=\"color: #333333\">(<\/span>currentDate<span style=\"color: #333333\">&gt;=<\/span>targetDate<span style=\"color: #333333\">)<\/span> <span style=\"color: #333333\">{<\/span>\r\n\t\t\t\t\ttimer<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">removeEventListener<\/span><span style=\"color: #333333\">(<\/span>TimerEvent<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">TIMER_COMPLETE<\/span><span style=\"color: #333333\">,<\/span> count<span style=\"color: #333333\">);<\/span>\r\n\t\t\t\t\t<span style=\"color: #888888\">\/\/just 00 the text fields so it looks &quot;over&quot;<\/span>\r\n\t\t\t\t\ttxt_day<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">text<\/span><span style=\"color: #333333\">=<\/span><span style=\"background-color: #fff0f0\">&quot;00&quot;<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t\t\t\ttxt_hour<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">text<\/span><span style=\"color: #333333\">=<\/span><span style=\"background-color: #fff0f0\">&quot;00&quot;<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t\t\t\ttxt_min<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">text<\/span><span style=\"color: #333333\">=<\/span><span style=\"background-color: #fff0f0\">&quot;00&quot;<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t\t\t\ttxt_sec<span style=\"color: #333333\">.<\/span><span style=\"color: #0000CC\">text<\/span><span style=\"color: #333333\">=<\/span><span style=\"background-color: #fff0f0\">&quot;00&quot;<\/span><span style=\"color: #333333\">;<\/span>\r\n\t\t\t\t<span style=\"color: #333333\">}<\/span>\r\n\r\n\t\t\t<span style=\"color: #333333\">}<\/span>\r\n\r\n\t\t<span style=\"color: #333333\">}<\/span>\r\n\r\n\t<span style=\"color: #333333\">}<\/span>\r\n<span style=\"color: #333333\">}<\/span>\r\n<\/pre>\n<\/div>\n<p>To use, simply create an instance of it, feed it the date you want it to count down to (format is YEAR, MONTH, DAY) and attach it to the stage via addChild.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #008800; font-weight: bold\">var<\/span> _counter:<span style=\"color: #333399; font-weight: bold\">Counter<\/span> <span style=\"color: #333333\">=<\/span> <span style=\"color: #008800; font-weight: bold\">new<\/span> <span style=\"color: #333399; font-weight: bold\">Counter<\/span><span style=\"color: #333333\">(<\/span><span style=\"color: #0000DD; font-weight: bold\">2011<\/span><span style=\"color: #333333\">,<\/span><span style=\"color: #0000DD; font-weight: bold\">4<\/span><span style=\"color: #333333\">,<\/span><span style=\"color: #0000DD; font-weight: bold\">11<\/span><span style=\"color: #333333\">);<\/span>\r\naddChild<span style=\"color: #333333\">(<\/span>_counter<span style=\"color: #333333\">);<\/span>\r\n<\/pre>\n<\/div>\n<p>Just make sure you have the movieclip (in the library) linked to the class.<br \/>\nSelect the clip > Properties and in &#8216;Class&#8217; point it to &#8216;Counter&#8217;.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/nathalielawhead.com\/noodles\/countdown2.jpg\" alt=\"Flash Servertime Countdown Timer\" \/><\/p>\n<p>That&#8217;s it!<\/p>\n<p>Source files <a href=\"http:\/\/nathalielawhead.com\/sourcefiles\/Countdown_Timer_To_Servertime\" target=\"_blank\">up for grabs <strong>HERE!<\/strong> <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been itching to do one for a long time since I keep being asked to do countdown timers&#8230; Then there&#8217;s always that pesky deadline that keeps me from actually not cutting corners and doin&#8217; it fo&#8217; realz. So dundid I didit! A countdown timer set to server time via PHP! (&#8230;You know, it should work, but I didn&#8217;t test it through n&#8217; through, just threw the servertime integration together this evening :S ). Source files up for grabs HERE! The deal is if you do a countdown in Flash, the Flash Date object is set to the user&#8217;s system&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":4522,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"","fifu_image_alt":"","footnotes":"","_links_to":"","_links_to_target":""},"categories":[12],"tags":[],"class_list":["post-1238","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-resources"],"_links":{"self":[{"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/posts\/1238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/comments?post=1238"}],"version-history":[{"count":17,"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/posts\/1238\/revisions"}],"predecessor-version":[{"id":3029,"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/posts\/1238\/revisions\/3029"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/media\/4522"}],"wp:attachment":[{"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/media?parent=1238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/categories?post=1238"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/tags?post=1238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}