LogoLogo
  • Home
  • Projects
  • About
  • Contact

Preloading my Life

Devon O. · January 03, 2008 · Actionscript, Life · 2 comments
3

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

C#
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};
        }
    }
}
Quick usage:
C#
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!");
        }
    }
}
  Facebook   Pinterest   Twitter   Google+
  • ImageInfo Desktop AIR Application
    February 18, 2008 · 0 comments
    2844
    1
    Read more
  • Playing Around with the New UndoManager
    May 01, 2010 · 11 comments
    3359
    5
    Read more
  • Sine Language
    January 30, 2008 · 0 comments
    1619
    3
    Read more
2 Comments:
  1. 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.

    Doc · January 04, 2008
  2. Very nice class :)

    I was looking for something like this and now i found it!

    Thanks devonair

    Mauredo · January 05, 2008

Sorry, the comment form is closed at this time.

Devon O. Wolfgang

AIR | Unity3D | AR/VR

Unity Certified Developer

Technical Reviewer of “The Essential Guide to Flash CS4 AIR Development” and “Starling Game Development Essentials”

Reviewer of “The Starling Handbook”

Unity Engineer at Touch Press.

Categories
  • Actionscript (95)
  • AIR (16)
  • Flash (99)
  • Games (7)
  • Liberty (13)
  • Life (53)
  • Shaders (20)
  • Unity3D (21)
Recent Comments
  • Devon O. on Unity Ripple or Shock Wave Effect
  • Feral_Pug on Unity Ripple or Shock Wave Effect
  • bavvireal on Unity3D Endless Runner Part I – Curved Worlds
  • Danielius Vargonas on Custom Post Processing with the LWRP
  • Luca G on Unity Ripple or Shock Wave Effect
Archives
  • December 2020 (1)
  • December 2019 (1)
  • September 2019 (1)
  • February 2019 (2)
  • December 2018 (1)
  • July 2018 (1)
  • June 2018 (1)
  • May 2018 (2)
  • January 2018 (1)
  • December 2017 (2)
  • October 2017 (1)
  • September 2017 (2)
  • January 2017 (1)
  • July 2016 (1)
  • December 2015 (2)
  • March 2015 (1)
  • September 2014 (1)
  • January 2014 (1)
  • August 2013 (1)
  • July 2013 (1)
  • May 2013 (1)
  • March 2013 (2)
  • December 2012 (1)
  • November 2012 (1)
  • September 2012 (3)
  • June 2012 (2)
  • May 2012 (1)
  • April 2012 (1)
  • December 2011 (2)
  • October 2011 (3)
  • September 2011 (1)
  • August 2011 (1)
  • July 2011 (1)
  • May 2011 (2)
  • April 2011 (2)
  • March 2011 (1)
  • February 2011 (1)
  • January 2011 (2)
  • December 2010 (3)
  • October 2010 (5)
  • September 2010 (1)
  • July 2010 (2)
  • May 2010 (5)
  • April 2010 (2)
  • March 2010 (7)
  • February 2010 (5)
  • January 2010 (5)
  • December 2009 (3)
  • November 2009 (1)
  • October 2009 (5)
  • September 2009 (5)
  • August 2009 (1)
  • July 2009 (1)
  • June 2009 (2)
  • May 2009 (6)
  • April 2009 (4)
  • March 2009 (2)
  • February 2009 (4)
  • January 2009 (1)
  • December 2008 (5)
  • November 2008 (2)
  • September 2008 (1)
  • August 2008 (6)
  • July 2008 (6)
  • June 2008 (9)
  • May 2008 (4)
  • April 2008 (3)
  • March 2008 (4)
  • February 2008 (9)
  • January 2008 (7)
  • December 2007 (6)
Copyright © 2017 Devon O. Wolfgang