A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: easy days, hours, mins countdown in text

  1. #1
    Member
    Join Date
    May 2003
    Posts
    40

    easy days, hours, mins countdown in text

    Hello,

    I have been searching this forum for countdown scripts, but they are either with images or just for seconds. What i want is a script that displays:

    xx "days" xx "minutes" xx "seconds"

    all just in plain text. I want to be able to change the names date, minutes and seconds in different languages for different swf's.

    Thanks in advance.

    Marcus

  2. #2
    Member
    Join Date
    May 2003
    Posts
    40
    ok i found a solution somewhere, so for the people that do a search in the future having the same question, here's the answer:

    Put the following code on a keyframe.

    Code:
    Date.prototype.countDown = function()
    {
            // Current time
            var now = new Date();
            
            // Calculating difference in ms
            var milisec = this - now;
            
            // Ms to days, hours, mins and secs
            var days = Math.floor(milisec / 86400000);
            milisec -= (days * 86400000);
            
            var hours = Math.floor(milisec / 3600000);
            milisec -= (hours * 3600000);
            
            var minutes = Math.floor(milisec / 60000);
            milisec -= (minutes * 60000);
            
            var seconds = Math.floor(milisec / 1000);
            milisec -= (seconds * 1000);
            
            // Create a string
            return days + " days " + hours + " hours " + minutes + ((minutes == 1) ? " minute " : " minutes ") + "and " + seconds + ((seconds == 1) ? " second" : " seconds");
    }
    
    // Usage
    // Create a date to countdown to
    var someDate = new Date(2006, 10, 1, 0, 0, 0);
    
    // Trace onEnterFrame
    this.onEnterFrame = function()
    {
            tf.text = someDate.countDown();
    }
    Now make a dynamic textfield and give it the instance name "tf"
    Bingo you have a countdown script!

    Marcus

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center