A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [F8] Countdown timer problem= NaN:NaN etc

  1. #1
    Junior Member
    Join Date
    Oct 2002
    Location
    Bristol UK
    Posts
    21

    [F8] Countdown timer problem= NaN:NaN etc

    Hi, I recently followed a video tutorial to the letter, to create a countdown timer in Flash8. All seemed to be going well until I completed the actionscript & hit 'preview' Instead of getting 00:00:00:00 (Days+Hours+Minutes+Seconds)
    I got a rather taunting (unexpected) NaN:NaN:NaN:NaN

    I'm an utter novice with script so I was left pretty stumped. I'll paste the exact code below the dotted line & hopefully some bright spark visiting here might be able to tell me how to fix the problem. I hope so.
    .................................................. .................................................. .....

    this.onEnterFrame = function() {
    var today:Date = new Date();
    var currentYear = today.getFullYear();
    var targetdate:Date = new Date(currentYear, 04, 20);
    var targetTime = targetDate.getTime();
    var timeLeft = targetTime-currentTime;
    var sec = Math.floor(timeLeft/1000);
    var min = Math.floor(sec/60);
    var hrs = Math.floor(min/60);
    var days = Math.floor(hrs/24);
    sec = String(sec%60);
    if (sec.length<2) {
    sec = "0"+sec;
    }
    min = String(min%60);
    if (min.length<2) {
    min = "0"+min;
    }
    hrs = String(hrs%24);
    if (hrs.length<2) {
    hrs = "0"+hrs;
    }
    days = String(days);
    var counter:String = days+":"+hrs+":"+min+":"+sec;
    time_txt.text = counter;
    }

    .................................................. .................................................. .
    For what its worth, there are no apparent problems as far as debugging is concerned. No errors flash up. The full tutorial can be found at this address...

    http://www.oman3d.com/tutorials/flas.../countdown.php

    If you can help, please give me a holler. Thanks
    Last edited by hiab-x; 02-14-2007 at 12:07 PM. Reason: unwanted smileys
    Hiab-X

  2. #2
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    well here is the problem NaN means Not a Number........it pops up when you do some funky math calculation that flash doesn't understand. find a new timer script there are a bunch out there that are wrote better than the above script.

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    there are a couple of mistakes. First actionscript is case sensitive:
    targetdate and targetDate are 2 separate vars.

    also you have this: var timeLeft = targetTime-currentTime;
    but currentTime is not defined anywhere.

    gparis

  4. #4
    Junior Member
    Join Date
    Oct 2002
    Location
    Bristol UK
    Posts
    21
    Thanks for the 'heads up', I'll correct the targetDate typo & re-check the video tutorial to see if I can identify the missing script. In the meanwhile, thanks for helping me.
    Hiab-X

  5. #5
    Junior Member
    Join Date
    Oct 2002
    Location
    Bristol UK
    Posts
    21
    Quote Originally Posted by gparis
    there are a couple of mistakes. First actionscript is case sensitive:
    targetdate and targetDate are 2 separate vars.

    also you have this: var timeLeft = targetTime-currentTime;
    but currentTime is not defined anywhere.

    gparis
    gparis, thanks very much for pointing out the errors in my actionscript. They were subtle & would've taken me significantly longer to spot without your well trained eye. The timer works a treat now. :-)
    Hiab-X

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