Copy link to clipboard
Copied
I have a digital timer counting down in the background of a website I'm working on. It's strictly an aesthetic thing and doesn't really serve any real purpose otherwise. I just want it to look like a working timer. Is there a way I can do this with actionscript so that I don't have to actually keyframe the numbers changing? I'm actually more of an animation guy and would usually just animate it timing down but that's probably more work than it's worth.
thanks
The example below displays countdown from 2 minutes to zero.
...import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.Timer;
var countDownDisplay:TextField;
var timer:Timer;
var date:Date;
init();
function init():void
{
countDownDisplay = new TextField();
countDownDisplay.defaultTextFormat = new TextFormat("Arial", 120, 0x008040);
countDownDisplay.multiline = countDownDisplay.wordWrap = false;
Copy link to clipboard
Copied
Search Google or even these forums using terms like "AS3 countdown tutorial"
Copy link to clipboard
Copied
The example below displays countdown from 2 minutes to zero.
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.Timer;
var countDownDisplay:TextField;
var timer:Timer;
var date:Date;
init();
function init():void
{
countDownDisplay = new TextField();
countDownDisplay.defaultTextFormat = new TextFormat("Arial", 120, 0x008040);
countDownDisplay.multiline = countDownDisplay.wordWrap = false;
countDownDisplay.border = true;
countDownDisplay.autoSize = "left";
countDownDisplay.x = countDownDisplay.y = 20;
countDownDisplay.text = "00:00 ";
addChild(countDownDisplay);
date = new Date(1000 * 120);
timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
}
function onTimer(e:TimerEvent):void
{
date.time -= timer.delay;
countDownDisplay.text = date.toUTCString().match(/\d\d:\d\d\s/)[0];
if (date.time <= 0)
{
timer.stop();
}
}
Copy link to clipboard
Copied
Would you be able to tell me which part of this coded dictates the start time? So like if I wanted to change it a higher number than 2 minutes?
Copy link to clipboard
Copied
The line
date = new Date(1000 * 120);
sets it to 2 minutes.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now