Copy link to clipboard
Copied
I have a working clock and calendar month/day week I would like to add a 05:00 minute count down timer to this but I would like to try and have timer countdown pulling time from the clock so that when it counts down the are both in synch with each other such as when second advances on clock the time decreases at same moment
this is my clock/date section
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;
//date variables
var month: Number = time.getMonth() + 1;
var day: Number = time.getDate();
var year: Number = time.getFullYear();
var monthStrg:String;
var dayStrg:String;
//date text
if (month < 10) {
monthStrg = "0" + month + "/";
} else {
monthStrg = month + "/"
}
if (day < 10) {
dayStrg = "0" + day + "/";
} else {
dayStrg = day + "/";
}
//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;
date_txt.text = monthStrg + dayStrg + year;
}
-------------------------------------------------------------------------------------------------------------------------------------------
this is timer like to combine with it time/date maybe pull count down from time same timer I am unsure about that
package {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.ui.Mouse;
public class timerClass extends MovieClip
{
var myTimer:Timer = new Timer(1000, 300);
var i:Number = 300;
public function timerClass()
{
//# constructor code
timerTxt.text = String("05:00");
myTimer.addEventListener(TimerEvent.TIMER, updateTime);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, TimerComplete);
startbutton.addEventListener(MouseEvent.CLICK, StartNow);
pausebutton.addEventListener(MouseEvent.CLICK, PauseNow);
restartbutton.addEventListener(MouseEvent.CLICK, restartNow);
}
private function updateTime(e:TimerEvent)
{
i--;
var totalSeconds:* = i;
var minutes:* = Math.floor(totalSeconds/60);
var seconds:* = totalSeconds % 60;
if(String(minutes).length < 2)
{
minutes = "0" + minutes;
if(String(seconds).length < 2)
seconds = "0" + seconds;
}
timerTxt.text = minutes + ":" + seconds;
}
private function TimerComplete(e:TimerEvent)
{
messageTxt.text = "PRESENTATION IS NOW OVER"
timerTxt.text = String("00:00");
}
private function StartNow(e:MouseEvent)
{ myTimer.start(); }
private function PauseNow(e:MouseEvent)
{ myTimer.stop(); }
private function restartNow(e: MouseEvent): void
{
myTimer.stop();
myTimer = new Timer(1000, 300);
myTimer.addEventListener(TimerEvent.TIMER, updateTime);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, TimerComplete);
i = 300;
messageTxt.text = "";
timerTxt.text = String("05:00");
}
} //#end Class
} //#end Package
any help /suggestion I would apprciate
jeff
Copy link to clipboard
Copied
do you still have this question?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now