A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Question regarding count up timer

  1. #1
    Junior Member
    Join Date
    Aug 2015
    Posts
    3

    Question regarding count up timer

    Trying to get a count-up timer to count the days, hours, minutes, and Seconds from a specified date. Anyone able to lend a hand on this?

    AS3 seems to not like my AS2 methods /cry

    Thanks in advance for any replies.

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Here is one I made a while ago, look at the code and input your selected time / date, perhaps even make it so you can enter the chosen date from the screen!!!!

  3. #3
    Junior Member
    Join Date
    Aug 2015
    Posts
    3
    Thank you so much for the reply and so fast too!
    Would you be able to let me know which part to take out if the date is a previous date to stop the timer from ending?

    Im trying to create a "Day's since incident" timer and the last incident was March 5th, 2015, but when I set that date in there it tells me "Time's Up".

    I know this should be on a dateText.text>today:date or something like this, but no matter what I change it seems to void out all of the code.

    Thanks in advance for any reply and again thanks for letting me poke at this file, looks great!

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Using the same file I supplied earlier, swap the code for this code and run it.
    PHP Code:
    var tYe:Number 2015;// Year;
    var tMo:Number 2;// Month : 0 = January;
    var tDa:Number 5;// Date;
    var tHo:Number 0;// Time - Hours - 24 hr clock;
    var tMi:Number 0;// Time- Minutes;
    var tSe:Number 0;// Time - Seconds;
    var tMs:Number 0;// Time - Milliseconds;

    var passedDate:Date = new Date(tYe,tMo,tDa,tHo,tMi);
    var 
    passedTime:Number passedDate.getTime();

    var 
    displayHour:String String(tHo);
    var 
    displayMins:String String(tMi);
    var 
    displayDate:String String(tDa);
    var 
    displayMont:String String(tMo 1);
    var 
    displayYear:String String(tYe);

    if (
    tHo 10)
    {
        
    displayHour "0" displayHour;
    }
    if (
    tMi 10)
    {
        
    displayMins "0" displayMins;
    }
    if (
    tDa 10)
    {
        
    displayDate "0" displayDate;
    }
    if (
    tMo 9)
    {
        
    displayMont "0" displayMont;
    }
    //dateText.text = "Since: " + displayHour + ":" + displayMins + " - " + displayDate + "/" + displayMont + "/" + displayYear;
    dateText.text "Since: " displayDate "/" displayMont "/" displayYear;

    addEventListener(Event.ENTER_FRAMEtimer);

    function 
    timer(e:Event):void
    {
        var 
    today:Date = new Date();
        var 
    nowTime:Number today.getTime();
        var 
    overTime:Number nowTime passedTime;

        var 
    sec Math.floor(overTime 1000);
        var 
    min Math.floor(sec 60);
        var 
    hours Math.floor(min 60);
        var 
    days Math.floor(hours 24);

        
    sec String(sec 60);
        if (
    sec.length 2)
        {
            
    sec "0" sec;
        }

        
    min String(min 60);
        if (
    min.length 2)
        {
            
    min "0" min;
        }

        
    hours String(hours 24);
        if (
    hours.length 2)
        {
            
    hours "0" hours;
        }

        
    days String(days);
        if (
    days.length 2)
        {
            
    days "0" days;
        }

        var 
    counter:String days ":" hours ":" min ":" sec;
        
    time_txt.text counter;


  5. #5
    Junior Member
    Join Date
    Aug 2015
    Posts
    3
    You are fast and efficient!

    Thank you so much for this, I really appreciate this a lot!

    Works like a charm...

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