Start/Stop button in AS3
Hi all i have a problem. I'm developing an iOS app, a scoreboard. I added a start button, a stop button and a reset button but there isn't enaugh space for the buttons. So i decided to create a Start/Stop Button.
Pratically, the button displays starts, i pass the mouse over and the timer start. Then the button displays Stop, i pass the mouse and the timer stop, then it displays another time start ecc.
How to do this?
import flash.events.*;
var ScoreHome:Number = 0;
HomeScore.text = scoreFormat(ScoreHome);
var ScoreGuest:Number = 0;
GuestScore.text = scoreFormat(ScoreHome);
var timePattern:RegExp = /\d\d\:\d\d(?=\s)/;
var secondPattern:RegExp = /(?<=\:)\d\d(?=\s)/;
var time:Date = new Date();
var timer2:Timer = new Timer(1000, 24);
timer2.addEventListener(TimerEvent.TIMER, countdownpossesso);
//timer2.start();
var timer:Timer = new Timer(1000, 360);
timer.addEventListener(TimerEvent.TIMER, countdown);
//timer.start();
ButtonplusHome.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandleradd);
ButtonminusHome.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerminus);
StartSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerSS);
StopSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerStS);
ResetSecond.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerRS);
Reset24.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler24);
ButtonplusGuest.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandleraddg);
ButtonminusGuest.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandlerminusg);
Seconds.text = "06:00";
Possesso.text = "24";
function countdown(e:TimerEvent):void
{
time.time = (timer.repeatCount - timer.currentCount) * 1000;
Seconds.text = time.toString().match(timePattern)[0];
if (timer.repeatCount == timer.currentCount) {
playSound(Event);
}
}
function countdownpossesso(e:TimerEvent):void
{
time.time = (timer2.repeatCount - timer2.currentCount) * 1000;
Possesso.text = time.toString().match(secondPattern)[0];
if (timer2.repeatCount == timer2.currentCount) {
playSound(Event);
}
}
function playSound(Event):void {
mySound.play()
timer.stop()
}
function scoreFormat(value:Number):String
{
return String(value <= 9 ? "0" + value : value);
}
function fl_MouseOverHandleradd(e:MouseEvent):void
{
ScoreHome++;
HomeScore.text = scoreFormat(ScoreHome);
}
function fl_MouseOverHandlerminus(e:MouseEvent):void
{
ScoreHome--;
HomeScore.text = scoreFormat(ScoreHome);
}
function fl_MouseOverHandlerSS(e:MouseEvent):void
{
timer.start()
timer2.start();
}
function fl_MouseOverHandlerStS(e:MouseEvent):void
{
timer.stop()
timer2.stop();
}
function fl_MouseOverHandlerRS(e:MouseEvent):void
{
timer.reset()
timer2.reset()
timer.start()
timer2.start()
timer.stop()
timer2.stop()
Seconds.text = "06:00";
Possesso.text = "24";
}
function fl_MouseOverHandleraddg(e:MouseEvent):void
{
ScoreGuest++;
GuestScore.text = scoreFormat(ScoreGuest);
}
function fl_MouseOverHandlerminusg(e:MouseEvent):void
{
ScoreGuest--;
GuestScore.text = scoreFormat(ScoreGuest);
}
function fl_MouseOverHandler24(e:MouseEvent):void
{
timer2.reset()
timer2.start()
Possesso.text = "24";
}
var mySound:Sound = new Buzzer();