Skip to main content
Inspiring
December 17, 2016
Answered

Start counting down!

  • December 17, 2016
  • 1 reply
  • 587 views

How can I start a countdown from a single button? I am trying to do, however, without success.

I would like the time to run alone after pressing a particular button and pause when it reaches zero. I did only the part of the dynamic text and the discount of numbers, however, everything manual.

can anybody help me?

//var

var score:uint

score = 7;

counting.text = "" + score.toString();

// EventList

up.addEventListener(MouseEvent.CLICK, up1);

// Actions

function up1(Event:MouseEvent): void {

       score -= 1;

       counting.text = "" + score.toString();

       if (score <= 0) {

       score = 0;

  }

  move.gotoAndStop(2);

}

The stopwatch starts in seven seconds, I would like after pressing the "up" button to start counting down to zero and then pause the time.

can anybody help me? Please?

This topic has been closed for replies.
Correct answer kglad
//var
var t:Timer=new Timer(1000,0);
t.addEventListener(TimerEvent.TIMER,timerF);
var score:uint score = 7;
counting.text = "" + score.toString(); 
// EventList
up.addEventListener(MouseEvent.CLICK, up1); 
// Actions
function up1(Event:MouseEvent): void {
t.start();
}

function timerF(e:TimerEvent):void{ 
score -= 1; 
counting.text = "" + score.toString();  
if (score <= 0) { 
score = 0;
t.stop(); 
}  else {
move.gotoAndStop(2);
}
}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
December 17, 2016
//var
var t:Timer=new Timer(1000,0);
t.addEventListener(TimerEvent.TIMER,timerF);
var score:uint score = 7;
counting.text = "" + score.toString(); 
// EventList
up.addEventListener(MouseEvent.CLICK, up1); 
// Actions
function up1(Event:MouseEvent): void {
t.start();
}

function timerF(e:TimerEvent):void{ 
score -= 1; 
counting.text = "" + score.toString();  
if (score <= 0) { 
score = 0;
t.stop(); 
}  else {
move.gotoAndStop(2);
}
}