0 Replies - 614 Views - Last Post: 12 September 2018 - 05:33 AM

#1 lukeprice   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-September 18

Making the seconds hand on a countdown timer spin rather than tick

Posted 12 September 2018 - 05:33 AM

Hello,

I have this ActionScript which is a simple countdown timer:
// "Countdown Timer" by Lemmyz

//variables
var count:int;
var timer:Timer=new Timer(1000);

//Sound objects
var alertSnd:Sound = new Alert();
var endSnd:Sound = new AlertEnd();
var startSnd:Sound = new AlertStart();

//Button event listeners
btnStart.addEventListener(MouseEvent.MOUSE_UP, timerStart);
btnStop.addEventListener(MouseEvent.MOUSE_UP, timerStop);
btnReset.addEventListener(MouseEvent.MOUSE_UP, timerReset);
btnOK.addEventListener(MouseEvent.MOUSE_UP, setCount);

//timer object
timer.addEventListener(TimerEvent.TIMER, rot);

//init
txt.text="Set countdown seconds";
btnStart.enabled=false;
btnReset.enabled=false;
btnStop.enabled=false;

//Functions
function setCount(evt:MouseEvent):void {
	count=parseInt(inputNum.text);
	btnStart.enabled=true;
	txt.text="Press START.\n"+count+" secs remaining"
}

function timerStart(evt:MouseEvent):void {
	endSnd.play();
	timer.start();
	btnStart.enabled=false;
	btnReset.enabled=false;
	btnOK.enabled=false;
	btnStop.enabled=true;
	
}

function timerStop(evt:MouseEvent):void {
	timer.stop();
	btnStop.enabled=false;
	btnReset.enabled=true;
	btnStart.enabled=true;
	btnStart.label="RESUME";
}

function timerReset(evt:MouseEvent):void {
	timer.stop();
	hand.rotation=0;
	count=parseInt(inputNum.text);
	btnStop.enabled=false;
	btnReset.enabled=false;
	btnOK.enabled=true;
	btnStart.label="START";
	txt.text="Timer reset to "+count+" secs. "+count+" secs remaining";
}

function rot(evt:TimerEvent):void {
	if (count==0) {
		timer.stop();
		hand.rotation=0;
		count=60;
		btnReset.enabled=false;
		btnStop.enabled=false;
		btnStart.label="START";
		btnStart.enabled=true;
		btnOK.enabled=true;
	} else {
		if (count==31||count==16) {
			alertSnd.play();
			count--;
			hand.rotation +=6;
		} else {
			count--;
			hand.rotation +=6;
		}
		if (count==0) {
			txt.text="Time's up! Timer is reset. Press START again.\n"+count+" secs remaining.";
			startSnd.play();
		} else {
			txt.text=count+" secs remaining";
		}
	}
}


At the moment the clock hand ticks every second. I would like it to spin smoothly. Is there a way of doing this? Thank you for any help in advance.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1