A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: [CS3] Countdown Timer [AS2]

  1. #1
    Student
    Join Date
    Jan 2008
    Posts
    13

    [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

  2. #2
    Student
    Join Date
    Jan 2008
    Posts
    13
    not like days or anythin.. just like a minute and seconds. for example 30 secs and just to zero

  3. #3
    Senior Member
    Join Date
    Mar 2000
    Posts
    116
    _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

  4. #4
    Student
    Join Date
    Jan 2008
    Posts
    13
    where do i put that coding? and will that show on my dynamic text box? it didnt seem to work.

  5. #5
    Student
    Join Date
    Jan 2008
    Posts
    13
    i just lied.. lol. did sumit noobish sorry. to change the position the time appears on screen do i just edit the coding?
    thanks

  6. #6
    Student
    Join Date
    Jan 2008
    Posts
    13
    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

  7. #7
    Senior Member
    Join Date
    Mar 2000
    Posts
    116
    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

  8. #8
    Junior Member
    Join Date
    Apr 2009
    Posts
    6
    How do you change the font of the text box that gets created because i want it in veranda.
    Thanks for the help.

    TSSgengar

  9. #9
    Junior Member
    Join Date
    Aug 2009
    Posts
    11
    How would you add milliseconds to the above code?

  10. #10
    Senior Member
    Join Date
    Mar 2000
    Posts
    116
    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

  11. #11
    Junior Member
    Join Date
    Aug 2009
    Posts
    11
    this is exactly what I am looking for thank you!
    How would I format the font?

  12. #12
    Senior Member
    Join Date
    Mar 2000
    Posts
    116
    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

  13. #13
    Junior Member
    Join Date
    Aug 2009
    Posts
    11
    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...

  14. #14
    Banned
    Join Date
    Nov 2002
    Posts
    60
    they have timers all ready built on here.

    check it out.
    http://flashden.net?ref=sixtyacura

  15. #15
    Junior Member
    Join Date
    Aug 2009
    Posts
    11
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center