-
How would I stop this timer when it hits zero and make it flash when done?
I'm definitely a newbie at actionscript and followed a tutorial to make this. But when the timer hits zero, it keeps counting past and starts counting upwards. How do I make it stop when it hits zero? I've also been asked if its possible to make it flash/blink when it does hit zero.
Code:
var targetDate:Date = new Date(2013, 07, 15, 24);
// Date = Year, Month (minus 1), Day, HourSet)
addEventListener(Event.ENTER_FRAME, loop);
function loop(e:Event):void
{
var nowDate:Date = new Date();
var ms:Number = targetDate.getTime() - nowDate.getTime();
var sec:Number = Math.floor(ms/1000);
var min:Number = Math.floor(sec/60);
var hr:Number = Math.floor(min/60);
var day:Number = Math.floor(hr/24);
sec = sec % 60;
min = min % 60;
hr = hr % 24;
daystxt.text = day.toString();
hrstxt.text = (hr < 10) ? "0"+hr.toString() : hr.toString();
minstxt.text = (min < 10) ? "0"+min.toString() : min.toString();
secstxt.text = (sec < 10) ? "0"+sec.toString() : sec.toString();
}
-
If I say pretty please, does that work?
-
.
Hi,
When which bit reaches 0 ???
But this may lead you in the right direction
PHP Code:
var targetDate:Date = new Date(2013,07,15,24); // Date = Year, Month (minus 1), Day, HourSet) addEventListener(Event.ENTER_FRAME, loop);
function loop(e:Event):void { var nowDate:Date = new Date(); var ms:Number = targetDate.getTime() - nowDate.getTime(); var sec:Number = Math.floor(ms/1000); var min:Number = Math.floor(sec/60); var hr:Number = Math.floor(min/60); var day:Number = Math.floor(hr/24);
sec = sec % 60; min = min % 60; hr = hr % 24;
daystxt.text = day.toString(); hrstxt.text = (hr < 10) ? "0" + hr.toString():hr.toString(); minstxt.text = (min < 10) ? "0" + min.toString():min.toString(); secstxt.text = (sec < 10) ? "0" + sec.toString():sec.toString(); if (sec > 0) { removeEventListener(Event.ENTER_FRAME, loop); trace("listener removed"); // do your blink code here or call function } }
Last edited by fruitbeard; 07-18-2013 at 11:45 AM.
Reason: typo
-
Dignitary
PHP Code:
if(nowDate==targetDate){
// do stuff
}
-
This worked:
Code:
if (ms <= 0) removeEventListener(Event.ENTER_FRAME, loop);
However when it stops, everything reads 01 01 01 01. Was hoping I could get it to display 00 00 00 00
-
Dignitary
Math
try
if (ms <= -1) removeEventListener(Event.ENTER_FRAME, loop);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|