A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: How would I stop this timer when it hits zero and make it flash when done?

  1. #1
    Junior Member
    Join Date
    Nov 2007
    Posts
    7

    How would I stop this timer when it hits zero and make it flash when done?

    I'm definitely a newbie at actionscript and followed a tutorial to make this. But when the timer hits zero, it keeps counting past and starts counting upwards. How do I make it stop when it hits zero? I've also been asked if its possible to make it flash/blink when it does hit zero.

    Code:
    var targetDate:Date = new Date(2013, 07, 15, 24);
    // Date = Year, Month (minus 1), Day, HourSet)
    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;
    	
    	daystxt.text = day.toString();
    	hrstxt.text = (hr < 10) ? "0"+hr.toString() : hr.toString();
    	minstxt.text = (min < 10) ? "0"+min.toString() : min.toString();
    	secstxt.text = (sec < 10) ? "0"+sec.toString() : sec.toString();
    }

  2. #2
    Junior Member
    Join Date
    Nov 2007
    Posts
    7
    If I say pretty please, does that work?

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

    When which bit reaches 0 ???

    But this may lead you in the right direction
    PHP Code:
    var targetDate:Date = new Date(2013,07,15,24);
    // Date = Year, Month (minus 1), Day, HourSet)
    addEventListener(Event.ENTER_FRAMEloop);

    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;

        
    daystxt.text day.toString();
        
    hrstxt.text = (hr 10) ? "0" hr.toString():hr.toString();
        
    minstxt.text = (min 10) ? "0" min.toString():min.toString();
        
    secstxt.text = (sec 10) ? "0" sec.toString():sec.toString();
        if (
    sec 0)
        {
            
    removeEventListener(Event.ENTER_FRAMEloop);
            
    trace("listener removed");
            
    // do your blink code here or call function
        
    }

    Last edited by fruitbeard; 07-18-2013 at 11:45 AM. Reason: typo

  4. #4
    Dignitary rynoe's Avatar
    Join Date
    Jan 2003
    Location
    Earth
    Posts
    760
    PHP Code:

      
    if(nowDate==targetDate){
             
    // do stuff
       

    [SIGPIC][/SIGPIC]

  5. #5
    Junior Member
    Join Date
    Nov 2007
    Posts
    7
    This worked:

    Code:
    if (ms <= 0) removeEventListener(Event.ENTER_FRAME, loop);
    However when it stops, everything reads 01 01 01 01. Was hoping I could get it to display 00 00 00 00

  6. #6
    Dignitary rynoe's Avatar
    Join Date
    Jan 2003
    Location
    Earth
    Posts
    760
    Math
    try
    if (ms <= -1) removeEventListener(Event.ENTER_FRAME, loop);
    [SIGPIC][/SIGPIC]

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