Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Darren Broe 17/04/2017
  2.  
  3. After seeing how inaccurate setInterval gets at frequencies lower than 1k,
  4. I decided to make the millisecond text field "cosmetic" only. The
  5. millisecond text field is just a movieClip with 50 frames, playing at 50
  6. frames a second. The "real" code is applied to the other 3 text fields.*/
  7.  
  8. startBtn.tabEnabled = false;
  9. stopBtn.tabEnabled = false;
  10. stopBtn._visible = false;
  11. milliseconds.stop();
  12.  
  13. var seconds:Number, minutes:Number, hours:Number;
  14. var interval:Number;
  15.  
  16. startBtn.onPress = function(){
  17.     startBtn._visible = false; stopBtn._visible = true;
  18.     seconds = 0; minutes = 0; hours = 0;
  19.     milliseconds.gotoAndPlay(1);
  20.     secondsText.text = "00"; minutesText.text = "00"; hoursText.text = "00";
  21.     interval = setInterval(timer,1000);
  22. }
  23.  
  24. stopBtn.onPress = function(){
  25.     startBtn._visible = true; stopBtn._visible = false;
  26.     milliseconds.stop();
  27.     clearInterval(interval);
  28. }
  29.  
  30. function timer():Void{
  31.     seconds++;
  32.    
  33.     if(seconds < 10){secondsText.text = "0"+seconds;}
  34.     else{secondsText.text = seconds;}
  35.     if(seconds >= 60){seconds = 0; secondsText.text = "00"; minutes++;}
  36.    
  37.     if(minutes < 10){minutesText.text = "0"+minutes;}
  38.     else{minutesText.text = minutes;}
  39.     if(minutes >= 60){minutes = 0; minutesText.text = "00"; hours++;}
  40.    
  41.     if(hours < 10){hoursText.text = "0"+hours;}
  42.     else{hoursText.text = hours;}
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement