Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

I NEED HELP GETTING CLOCK TO COUNT DOWN

Community Beginner ,
Apr 06, 2019 Apr 06, 2019

I JUST LIKE TO SIMPLY CHANGE THIS SO CLOCK WILL RUN BACKWARDS

import flash.utils.Timer; 
import flash.events.TimerEvent; 
 
var looper: Timer = new Timer(100); 
looper.start(); 
looper.addEventListener(TimerEvent.TIMER, loopF);

function loopF(event:TimerEvent):void{ 
var time: Date = new Date();

//time variables

var hours:* = time.getHours(); 
var minutes:* = time.getMinutes(); 
var seconds:* = time.getSeconds(); 
var hourStrg:String;  
var minuteStrg:String;
var secondStrg:String;

//time text
 
if(String(seconds).length < 2){
seconds = "0" + seconds;
}
if(String(minutes).length < 2){
minutes = "0" + minutes;
}
if(hours > 11){
ampm_txt.text = "PM";
} else {
ampm_txt.text = "AM";
}
if(hours > 12){
hours = hours - 12;
}
if (String(hours).length < 2){
hours = "0" + hours;
}
time_txt.text = hours + ":" + minutes + ":" + seconds;
     
}

TOPICS
ActionScript
372
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 07, 2019 Apr 07, 2019
LATEST

this is approximate for a date countdown.  it's simpler if you just want to countdown from say 60 seconds.

import flash.utils.Timer; 
import flash.events.TimerEvent; 
 

var futureTime:int = new Date(whateveryear,whatevermonth,whateverdate).time;  //edit these 3 parameters

var looper: Timer = new Timer(100); 
looper.start(); 
looper.addEventListener(TimerEvent.TIMER, loopF);

function loopF(event:TimerEvent):void{ 
var t:int = Math.round(futureTime-new Date().time/1000);

if(t>0){

displayF(t);

} else {

looper.stop();

}

}

function displayF(t:int):void{

var d:Date = new Date(t);

time_txt.text = (t.fullYear-1970)+" years"+" "+t.month+" months"+" "+t.date+" days"+" "+padF(t.hours)+" hours"+" "+padF(t.minutes)+" minutes"+" "+padF(t.seconds)+" seconds";

}

function padF(i:int):String{

var s:String = i.toString();

while(s.length<2){

s+="0";

}

return s;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines