How to Make a Countdown Clock on Flash

Written by willa dunn
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Make a Countdown Clock on Flash
Create your own vritual timer using Flash. (Burke/Triolo Productions/Brand X Pictures/Getty Images)

Adobe Flash includes the Flash scripting language, ActionScript, which controls and creates the functionality in animations. Perhaps you want to include a countdown clock in your multimedia project. A countdown clock can provide your users with day, hour, minute and second updates on the time remaining until a certain event. Make a countdown clock in Flash using ActionScript functions and methods.

Skill level:
Moderate

Other People Are Reading

Instructions

  1. 1

    Launch Flash. Select "File" and "New" to create a new project. Select the "Flash File (ActionScript 3.0)" option and click "OK."

  2. 2

    Select the Text tool from the Tools panel and create a text box. Set the text area to "Dynamic Text" or "TLF Text" from the "Properties" panel. Type "clockTxt" for the "Instance Name."

  3. 3

    Click on the first frame of the timeline. Open the Actions panel by pressing "F9," Type the ActionScript code to create a clock that counts down to the next year. The lines that begin with // are descriptions, not part of the code:

    // register the function

    addEventListener('enterFrame',clock_handler);

    // this is called repeatedly

    function clock_handler(evt:Event):void{

    // the current date
    
    var today:Date = new Date();
    
    // the current Year
    
    var current Year = today.getFullYear();
    
    // the current time
    
    var current Time = today.getTime();
    
    // make and store the end date (next new year)
    

    // modify to fit your need

    var end Date:Date = new Date(currentYear+1, 0, 1);
    
    var end Time = endDate.getTime();
    
    // time left
    
    var time Left = end Time-current Time;
    
    var sec = Math.floor(time Left/1000);
    
    var min = Math.floor(sec/60);
    
    var hours = Math.floor(min/60);
    
    var days = Math.floor(hours/24);
    
    
    
    // result of remaining value variable.  convert seconds to string
    
    sec = String(sec%60);
    
    
    
    // if reduced < 2 add a 0
    
    if (sec.length<2) {
    
        sec = "0"+sec;
    
    }
    
    
    
    min = String(min%60);
    
    if (min.length<2) {
    
        min = "0"+min;
    
    }
    
    
    
    hours = String(hours%24);
    
    if (hours.length<2) {
    
        hours = "0"+hours;
    
    }
    
    
    
    days = String(days);
    
    
    
    if (time Left>0) {
    
        // combine values into one string
    
        var counter:String = days+":"+hours+":"+min+":"+sec;
    
        clockTxt.text = counter;
    
    } else {
    
        trace("It's A Brand New Year!");
    
        var new Time:String = "00:00:00:00";
    
        clockTxt.text = new Time;
    
        removeEventListener('enterFrame',clock_handler);
    
    }
    

    }

  4. 4

    Select "Control" and "Test Movie" to test the countdown clock.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.