-
[CS3] Countdown Timer [AS2]
Ok.. been looking for a countdown timer for a prank im tryin to pull :P. i just want a certain time to countdown and then do watever. i have made a dynamic text box but dno the coding for it... any help ? thanks
-
not like days or anythin.. just like a minute and seconds. for example 30 secs and just to zero
-
_root.createTextField("timer", _root.getNextHighestDepth(), 5, 0, 100, 25);
_root.timer.text = 30; // set this to what ever you want to count down from
function updateTimer() {
if(int(_root.timer.text) > 0) {
_root.timer.text = int(_root.timer.text) - 1;
}
else {
trace("30 seconds have passed!!");
clearInterval(myInterval);
delete myInterval;
}
}
myInterval = setInterval(updateTimer, 1000);
Webpages:
www.winningsolutionsinc.com
-
where do i put that coding? and will that show on my dynamic text box? it didnt seem to work.
-
i just lied.. lol. did sumit noobish sorry. to change the position the time appears on screen do i just edit the coding?
thanks
-
god just keep answering my own posts here.. problem solved.. thanks alot.. wat about if i wanted to add minutes and have always 00:00:00?? any help
-
we're getting a little deeper here.. The interval is setup to do seconds.. so lets say you wanted to do a minute countdown.. the easiest way would be to have two "hidden" variables for your minute and second counter.. then do a string concat (+) to add in the :'s
this will handle minutes
_root.createTextField("timer", _root.getNextHighestDepth(), 5, 0, 100, 25);
_root.myMinutes = 59; //set to number of starting minutes
_root.mySeconds = 0; //set to number of starting seconds
_root.timer.text = twoDigitString(myMinutes) + ":" + twoDigitString(mySeconds);
function updateTimer() {
if(_root.mySeconds == 0) {
if(_root.myMinutes == 0) {
_root.timer.text = "DONE!";
clearInterval(myInterval);
delete myInterval;
}
else {
_root.myMinutes = _root.myMinutes - 1;
_root.mySeconds = 59;
_root.timer.text = twoDigitString(myMinutes) + ":" + twoDigitString(mySeconds);
}
}
else {
_root.mySeconds = _root.mySeconds - 1;
_root.timer.text = twoDigitString(myMinutes) + ":" + twoDigitString(mySeconds);
}
}
// This function will make sure we have two number places in our number if it's less then 9(0#)
function twoDigitString(myNumber) {
myTemp = String(myNumber);
if(myTemp.length == 1) {
myTemp = "0" + myTemp;
}
return myTemp;
}
myInterval = setInterval(updateTimer, 1000);
Webpages:
www.winningsolutionsinc.com
-
How do you change the font of the text box that gets created because i want it in veranda.
Thanks for the help.
TSSgengar
-
How would you add milliseconds to the above code?
-
I haven't coded in AS2 in a while.. and this post was made ohh.. a year ago.. but.. I will give the milliseconds a try.. NOTE: I wouldn't suggest doing this. Having a setInterval firing every 1 millisecond seems like it would tax the hell out of a processor. I have bolded the changes. CHEERS!
_root.createTextField("timer", _root.getNextHighestDepth(), 5, 0, 100, 25);
_root.myMinutes = 59; //set to number of starting minutes
_root.mySeconds = 0; //set to number of starting seconds
_root.myMilliseconds = 0 //set to number of starting milliseconds
_root.timer.text = twoDigitString(myMinutes) + ":" + twoDigitString(mySeconds) + ":" + myMilliseconds;
function updateTimer() {
if(_root.myMilliseconds == 0) {
if(_root.mySeconds == 0) {
if(_root.myMinutes == 0) {
_root.timer.text = "DONE!";
clearInterval(myInterval);
delete myInterval;
}
else {
_root.myMinutes = _root.myMinutes - 1;
_root.mySeconds = 59;
_root.timer.text = twoDigitString(myMinutes) + ":" + twoDigitString(mySeconds) + ":" + myMilliseconds;
}
}
else {
_root.mySeconds = _root.mySeconds - 1;
_root.myMilliseconds = 999;
_root.timer.text = twoDigitString(myMinutes) + ":" + twoDigitString(mySeconds) + ":" + myMilliseconds;
}
}
else {
_root.myMilliseconds = _root.myMilliseconds - 1;
_root.timer.text = twoDigitString(myMinutes) + ":" + twoDigitString(mySeconds) + ":" + myMilliseconds;
}
}
// This function will make sure we have two number places in our number if it's less then 9(0#)
function twoDigitString(myNumber) {
myTemp = String(myNumber);
if(myTemp.length == 1) {
myTemp = "0" + myTemp;
}
return myTemp;
}
myInterval = setInterval(updateTimer, 1);
Last edited by @; 08-17-2009 at 11:39 AM.
Webpages:
www.winningsolutionsinc.com
-
this is exactly what I am looking for thank you!
How would I format the font?
-
something like this..
var timerFormat = new TextFormat();
timerFormat.font = "Courier"; //replace with what ever font.. KEEP IN MIND THE SYSTEM HAS TO HAVE THE FONT!
timer.setTextFormat(timerFormat);
Webpages:
www.winningsolutionsinc.com
-
EEISH! thanks for the heads up on the font, that's going to throw a curve ball now. Was playing around with digital font styles...
-
they have timers all ready built on here.
check it out.
http://flashden.net?ref=sixtyacura
-
How can I add the var time format to my dynamic text container?
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
|