A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [CS3] Timer Not Counting Up

  1. #1
    Member
    Join Date
    Mar 2008
    Posts
    67

    [CS3] Timer Not Counting Up

    I'm trying to make a timer for a puzzle I made and I can't get it to count at all. I just get "0:0:0". Here's my code:

    Code:
    function oneUp() {
    	seconds++;
    	trace("interval called");
    }
    
    
    setInterval(oneUp,1000);
    
    
    stop();
    
    var seconds = 0;
    var minutes = 0;
    var hours = 0;
    
    timeDisplay = hours+":"+minutes+":"+seconds;
    
    if (seconds=60) {
    	seconds = 0;
    	minutes++;
    }
    if (minutes=60) {
    	minutes = 0;
    	hours++;
    }
    if (seconds<10) {
    	seconds = "0"+seconds;
    }
    if (minutes<10) {
    	minutes = "0"+minutes;
    }
    if (hours<10) {
    	hours = "0"+hours;
    }
    I also uploaded an example of what I got. Thanks in advance for any help.
    Attached Files Attached Files

  2. #2
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Working code, notice all the changes I made to make this property work as a timer, especially the logic of the interval function.

    PHP Code:
    stop();
    var 
    timeInt setInterval(updateTime,1000);
    var 
    seconds 0;
    var 
    minutes 0;
    var 
    hours 0;

    timeDisplay.text "00:00:00";

    function 
    updateTime() {
        
    seconds++;
        if (
    seconds==60) {
            
    seconds 0;
            
    minutes++;
        }
        if (
    minutes==60) {
            
    minutes 0;
            
    hours++;
        }
        
        
    secStr seconds;
        
    minStr minutes;
        
    hourStr hours;
        
        if (
    seconds<10secStr String("0"+seconds);
        if (
    minutes<10minStr String("0"+minutes);
        if (
    hours<10hourStr String("0"+hours);
        
        
    timeDisplay.text hourStr+":"+minStr+":"+secStr;


  3. #3
    Member
    Join Date
    Mar 2008
    Posts
    67
    That doesn't seem to be working. All it does is show "00:00:00" and doesn't go up.

  4. #4
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    I noticed you have the var field filled in your text properties, never put anything in there - remove it and it should work.

  5. #5
    Member
    Join Date
    Mar 2008
    Posts
    67
    That did it! Thanks!

  6. #6
    Member
    Join Date
    Mar 2008
    Posts
    67
    Forgive the double post, but how can I stop the timer from out side of the movie clip in the main time line? I tried:

    Code:
    pCounter.clearInterval(timeInt);
    pCounter.clearInterval(updateTime);
    But that didn't work.

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