Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Darren Broe 17/04/2017
- After seeing how inaccurate setInterval gets at frequencies lower than 1k,
- I decided to make the millisecond text field "cosmetic" only. The
- millisecond text field is just a movieClip with 50 frames, playing at 50
- frames a second. The "real" code is applied to the other 3 text fields.*/
- startBtn.tabEnabled = false;
- stopBtn.tabEnabled = false;
- stopBtn._visible = false;
- milliseconds.stop();
- var seconds:Number, minutes:Number, hours:Number;
- var interval:Number;
- startBtn.onPress = function(){
- startBtn._visible = false; stopBtn._visible = true;
- seconds = 0; minutes = 0; hours = 0;
- milliseconds.gotoAndPlay(1);
- secondsText.text = "00"; minutesText.text = "00"; hoursText.text = "00";
- interval = setInterval(timer,1000);
- }
- stopBtn.onPress = function(){
- startBtn._visible = true; stopBtn._visible = false;
- milliseconds.stop();
- clearInterval(interval);
- }
- function timer():Void{
- seconds++;
- if(seconds < 10){secondsText.text = "0"+seconds;}
- else{secondsText.text = seconds;}
- if(seconds >= 60){seconds = 0; secondsText.text = "00"; minutes++;}
- if(minutes < 10){minutesText.text = "0"+minutes;}
- else{minutesText.text = minutes;}
- if(minutes >= 60){minutes = 0; minutesText.text = "00"; hours++;}
- if(hours < 10){hoursText.text = "0"+hours;}
- else{hoursText.text = hours;}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement