Results 1 to 4 of 4

Thread: Flash countdown timer tutorial

  1. #1
    Join Date
    Aug 2009
    Posts
    7

    Flash countdown timer tutorial

    Hi,

    I need to create a countdown timer in Flash to view it on a web page.
    I am looking for an article or a tutorial to show the countdown timer in flash. I hope someone will help me with this.

    Thanks in advance.

  2. #2
    Join Date
    Apr 2008
    Posts
    22

    Re: Flash countdown timer tutorial

    Flash simple timer / countdown

    On the left we have a timer, on the right a countdown.

    Let's see how to do it.

    First, I created two dynamic text items, the one on the left instanced as count and the one on the right instanced as count_down.

    Then, in the first frame there is this simple actionscript:

    Code:
    ACTIONSCRIPT:
    
    
          start_time = getTimer();
    
          countdown = 7200000;
    
          onEnterFrame = function () {
    
              elapsed_time = getTimer()-start_time;
    
              _root.count.text = time_to_string(elapsed_time);
    
              _root.count_down.text = time_to_string(_root.countdown-elapsed_time);
    
          };
    
          function time_to_string(time_to_convert) {
    
              elapsed_hours = Math.floor(time_to_convert/3600000);
    
              remaining = time_to_convert-(elapsed_hours*3600000);
    
              elapsed_minutes = Math.floor(remaining/60000);
    
              remaining = remaining-(elapsed_minutes*60000);
    
              elapsed_seconds = Math.floor(remaining/1000);
    
              remaining = remaining-(elapsed_seconds*1000);
    
              elapsed_fs = Math.floor(remaining/10);
    
              if (elapsed_hours<10) {
    
                  hours = "0"+elapsed_hours.toString();
    
              } else {
    
                  hours = elapsed_hours.toString();
    
              }
    
              if (elapsed_minutes<10) {
    
                  minutes = "0"+elapsed_minutes.toString();
    
              } else {
    
                  minutes = elapsed_minutes.toString();
    
              }
    
              if (elapsed_seconds<10) {
    
                  seconds = "0"+elapsed_seconds.toString();
    
              } else {
    
                  seconds = elapsed_seconds.toString();
    
              }
    
              if (elapsed_fs<10) {
    
                  hundredths = "0"+elapsed_fs.toString();
    
              } else {
    
                  hundredths = elapsed_fs.toString();
    
              }
    
              return hours+":"+minutes+":"+seconds+":"+hundredths;
    
          }
    Line 1: Initialize the variable start_time with the current time value

    Line 2: Initialize the variable countdown with the amount of milliseconds I want to start the countdown. In this case, since an hour has 3600 seconds or 3600000 milliseconds, the countdown will start from 2 hours

    Line 3: Function to be executed at every frame

    Line 4: Calculate the difference between the actual time and the start_time value. This is actually the elapsed time.

    Lines 5-6: count and count_down text values are updated with the result of a the function time_to_string (a function I created). count will be the elapsed time, while count_down will be the difference from the countdown variable and the elapsed time. Please note that every time explained here is intended to be in milliseconds.

    Let's examine the main function:

    Line 9: Calculate elapsed hours dividing the time to convert (function's argument) by 3600000, the number of milliseconds in an hour

    Line 10: Calculate remaining time without the elapsed hours

    Lines 11-12: Some thing with the minutes, dividing the remaining time by 60000, the number of milliseconds in a minute

    In the same way I calculate the seconds and the 1/100 of seconds. Lines from 16 to 35 just format the string showing the time.

  3. #3
    Join Date
    Apr 2008
    Posts
    21

    Re: Flash countdown timer tutorial

    Creating a Countdown Timer in Flash

    I think this video tutorial would help you better.

  4. #4
    Join Date
    May 2008
    Posts
    33

    Re: Flash countdown timer tutorial

    Here is a tutorial you will find much more helpful

    Date Countdown Timer

    Here you will learn to create a countdown timer which counts down from the current date and time to a specific date and time in the future. This example will use days, hours, minutes, seconds and even milliseconds retrieved from Flash's Date object to calculate that countdown. But, not only will you learn what is needed to calculate that countdown; you will also learn how to incorporate custom images to represent your numbers in that countdown.

    Two parts to this tutorial:

    1. First there's making the graphics, which doesn't seem that difficult (though there's some tricks in helping with that.)

    2. Then there's the coding to make it all work, which actually has some tricks of its own as well.

Similar Threads

  1. Replies: 3
    Last Post: 02-07-2012, 04:08 PM
  2. How to create countdown timer in Excel
    By Rao's in forum Windows Software
    Replies: 1
    Last Post: 07-01-2012, 12:23 PM
  3. Replies: 4
    Last Post: 05-02-2011, 11:17 PM
  4. Refresh with the help of countdown timer
    By Sheravat in forum Software Development
    Replies: 5
    Last Post: 08-09-2010, 10:01 PM
  5. Countdown timer
    By john83 in forum Software Development
    Replies: 4
    Last Post: 25-08-2010, 09:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,828,408.97568 seconds with 16 queries