This has got to be the longest preloader ever – the amount of time I have left until I’m out of the Navy:
Which reminds me - here's a handy AS3 class to create a countdown from now until some chosen date (passed as constructor argument):
CountDown.as
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
package com.onebyonedesign.utils { public class CountDown { private var _targetDate:Date; public function CountDown(d:Date):void { _targetDate = d; } /** * * @return An object with the properties: days, hours, minutes, and seconds */ public function getTime():Object { var now:Date = new Date(); var secs:Number = (_targetDate.getTime() - now.getTime()) / 1000; return secondsToTime(secs); } private function secondsToTime(secs:Number):Object { var min:Number = Math.floor(secs / 60); var hour:Number = Math.floor(min / 60); var day:Number = Math.floor(hour / 24); min = min % 60; hour = hour % 24; var sec:Number = Math.floor(secs % 60); var days:String = day < 10 ? "0" + day : day.toString(); var seconds:String = sec < 10 ? "0" + sec : sec.toString(); var minutes:String = min < 10 ? "0" + min : min.toString(); var hours:String = hour < 10 ? "0" + hour : hour.toString(); return {days:days, hours:hours, minutes:minutes, seconds:seconds}; } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
package { import com.onebyonedesign.utils.CountDown; import flash.display.Sprite; import flash.events.TimerEvent; import flash.utils.Timer; public class CountdownExample extends Sprite { private var birthday:Date = new Date(2008, 11, 28); private var cd:CountDown; public function CountdownExample():void { cd = new CountDown(birthday); beginCount(); } private function beginCount():void { var timer:Timer = new Timer(10000); timer.addEventListener(TimerEvent.TIMER, showCount); timer.start(); } private function showCount(te:TimerEvent):void { var time:Object = cd.getTime(); trace ("Only " + time.days + " days until Devon's birthday!"); } } } |
At least there is more green than red. This loader bar and it’s progress reminds me of installing things on Vista. Or rather, trying to install things on Vista.
Very nice class :)
I was looking for something like this and now i found it!
Thanks devonair