A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Stopwatch issue

  1. #1
    Member
    Join Date
    Jan 2010
    Posts
    40

    Stopwatch issue

    Hi, I'm trying to get my stopwatch to work and convert the milliseconds into minutes and seconds but the output text is only showing 00:00.
    Here's the code

    Actionscript Code:
    var myTimer:Timer=new Timer(1000, 0);

    myTimer.addEventListener(TimerEvent.TIMER, stopWatch);
    start_btn.addEventListener(MouseEvent.CLICK, startClock);

    function stopWatch(event:TimerEvent):void {
    var now:Timer = new Timer(1000, 0);
    var timeElapsed:Number = myTimer.currentCount + now.currentCount;
    var seconds:Number = Math.floor(timeElapsed / 1000);
    var minutes:Number = Math.floor(seconds / 60);

    seconds %= 60;
    minutes %= 60;

    var sec:String = seconds.toString();
    var min:String = minutes.toString();

    if(sec.length < 2){
        sec = "0" + sec;
    }
       
    if(min.length < 2){
        min = "0" + min;
    }
       
    var time:String = min + ":" + sec;
    //////////////////////////////
    myText_txt.text=time;
    trace(time)
    }

    function startClock(event:MouseEvent):void {
        myTimer.start();
        }

    Any suggestions please?

  2. #2
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    What if you add this to the stopWatch function...
    Actionscript Code:
    seconds = seconds + 1;
    if(seconds > 59) {
        minutes = minutes + 1;
    }
    Wile E. Coyote - "Clear as mud?"

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    1
    var seconds:Number = timeElapsed / 1000 % 60;
    var minutes:Number = timeElapsed / 1000 / 60;
    seconds %= 60;
    minutes %= 60;

  4. #4
    Member
    Join Date
    Jan 2010
    Posts
    40
    thx guys

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