all groups > flash actionscript > september 2004 >
You're in the

flash actionscript

group:

countdown timer - HELP!


countdown timer - HELP! scriptKid
9/2/2004 8:12:26 PM
flash actionscript:
hello,

i'm trying to write a timer that counts down from 10 minutes then start over.
i just want it to decrement the minutes, seconds and milliseconds. i have the
milliseconds "sort of" working and the seconds can countdown, but i can't
control where the seconds and minutes start. i want them to start at 10 for
minutes and and the seconds at 00 then go to 59. right now, all i can get the
seconds and minutes to get those from the computer.

my solution for my timer is: set minutes to 10 and then when getMinutes()
changes, decrement by 1, the same with seconds. i just dont know the proper
syntax to get my code to work. the code for the onEnterFrame part is really
messed up right now cause i don't know where to go....

thanks!
--kevin

_root.onLoad = function() {
loadItUp();
function loadItUp(minutes, seconds) {
test = new Date();
sec1 = test.getSeconds();
if (sec1<59) {
while (sec1<59 && sec1 != 0) {
sec1++;
//trace(sec1);
}
}
if (sec1 == 59) {
//trace("sec1 = 59");
}
if (sec1 == 0) {
//trace("sec1 = 0");
}
min1 = test.getMinutes();
if (min1 != 10) {
if (min1>10) {
while (min1>10) {
min1--;
//trace(min1);
}
}
if (min1<10) {
min1++;
//trace(min1);
}
}
//trace(min1);
//trace(sec1);
return workItOut(min1, sec1);
}
};
///////////////////////////////
_root.onEnterFrame = function() {
workItOut();
function workItOut() {
bloopy = new Date();
millisecsier = 999-(Math.floor(bloopy.getMilliseconds()));
if (millisecsier<100) {
myTextBox.text = ":0"+millisecsier;
} else if (millisecsier<10) {
myTextBox.text = ":00"+millisecsier;
} else if (millisecsier == 0) {
myTextBox.text = ":000"+millisecsier;
} else {
myTextBox.text = ":"+millisecsier;
}
///////////////////////////////
gloopy = bloopy.getSeconds();
//trace("GLOOPY!");
myTextBox2.text = gloopy;
myTextBox2.onChanged = function() {
myTextBox2.text = ;
//gloopier = sec1--;
trace(gloopier);


};
//myTextBox2.text = gloopier;
///////////////////////////////
sloopy = bloopy.getMinutes();
//trace("SLOOPY!");
if (sec1 == 00) {
min1--;
trace(min1);
myTextBox3.text = min1;
}
//sloopier = min1;
//myTextBox3.text = sloopy;
}
};
///////////////////////////////
Re: countdown timer - HELP! Jensen
9/3/2004 11:27:47 AM
Hi there!

Create a dynamic textfield and call it
TimeOutput
That is only for your visual feedback. Change the displayTime function if
you want it to do something else.
Add the following code.
Change input parameters of countDown(10, 0, displayTime); if you want some
other countdown.

function countDown(minutes, seconds, reportTime) {
var TimerObj= new Date();
var endTime = TimerObj.getTime()+((minutes*60)+seconds)*1000;
var countDownId = setInterval(
function() {
var TimerObj = new Date();
var currentTime = TimerObj.getTime();
if (currentTime >= endTime) {
clearInterval(countDownID);
reportTime(0);
countDownDone();
} else {
reportTime(endTime - currentTime);
}
},80);
}

function countDownDone() {
trace("Done!");
}

function displayTime(totalTime) {
var milliseconds = totalTime % 1000;
var tmpSec = (totalTime - milliseconds)/1000;
var seconds = tmpSec % 60;
var minutes = (tmpSec - seconds)/60;
TimeOutput.text = minutes+":"+seconds+":"+milliseconds;
}

countDown(10, 0, displayTime);

/Jensen/

Re: countdown timer - HELP! scriptKid
9/3/2004 5:23:54 PM
thanks so much jensen!!!

i have to program but i'm not a programmer, if you know what i mean. so it means a lot that people like you help guys like me out on this forum.

thanks!
AddThis Social Bookmark Button