A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Count Down Timer problem

  1. #1
    Junior Member
    Join Date
    Jul 2007
    Posts
    1

    Exclamation Count Down Timer problem

    So I have a count down timer, which is working fine except for once the clock reachers 00:00:00:00 it starts counting backwards. Here is my code if anyone can help me get it to stop once it reaches 0 I would be most appreciative!

    Actionscript Code:
    var targetDate:Date = new Date(2011, 6, 11, 10, 41);

    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;
       
        daytxt.text = day.toString();
        hrtxt.text = (hr < 10) ? "0"+hr.toString() : hr.toString();
        mintxt.text = (min < 10) ? "0"+min.toString() : min.toString();
        sectxt.text = (sec < 10) ? "0"+sec.toString() : sec.toString();
    }

  2. #2
    Senior Member
    Join Date
    Dec 2010
    Posts
    121
    You can try to use the removeEventListner method to stop the loop as soon as the hour bit or day bit reaches 0.

  3. #3
    Member
    Join Date
    Dec 2009
    Posts
    84
    You could end the loop function with:
    Code:
    if(daytxt.text =="0" && hrtxt.text =="0" && mintxt.text =="0" && sectxt.text=="0"){
         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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center