Highlighted

trying to make reset button to reset timer back to 05:00

Community Beginner ,
Mar 10, 2019

Copy link to clipboard

Copied

start and stop works but cant find a way to get restart button to work

package  {

import flash.display.MovieClip;

import flash.utils.Timer;

import flash.events.TimerEvent;

import flash.events.MouseEvent;

import flash.ui.Mouse;

public class timerClass extends MovieClip {

  var myTimer:Timer = new Timer(1000, 300);

  var i:Number = 300;

public function timerClass() {

   // constructor code

   timerTxt.text = String("05:00");

   myTimer.addEventListener(TimerEvent.TIMER, updateTime);

   myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, TimerComplete);

   startbutton.addEventListener(MouseEvent.CLICK, StartNow);

   pausebutton.addEventListener(MouseEvent.CLICK, PauseNow);

   restartbutton.addEventListener(MouseEvent.CLICK, restartNow);

   }

  private function updateTime(e:TimerEvent):void{

   i--;

   var totalSeconds:* = i;

   var minutes:* = Math.floor(totalSeconds/60);

   var seconds:* = totalSeconds % 60;

   if(String(minutes).length < 2)

    minutes = "0" + minutes;

    if(String(seconds).length < 2)

    seconds = "0" + seconds;

   timerTxt.text = minutes + ":" + seconds;

  }

 

  private function TimerComplete(e:TimerEvent):void{

   messageTxt.text = "PRESENTATION IS NOW OVER"

   timerTxt.text = String("00:00");

  }

  private function StartNow(e:MouseEvent):void{

   myTimer.start();

  }

  private function PauseNow(e:MouseEvent):void{

   myTimer.stop();

 

  }

   private function restartNow(e:MouseEvent):void{

   }

  }

}

TOPICS
ActionScript

Views

397

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

trying to make reset button to reset timer back to 05:00

Community Beginner ,
Mar 10, 2019

Copy link to clipboard

Copied

start and stop works but cant find a way to get restart button to work

package  {

import flash.display.MovieClip;

import flash.utils.Timer;

import flash.events.TimerEvent;

import flash.events.MouseEvent;

import flash.ui.Mouse;

public class timerClass extends MovieClip {

  var myTimer:Timer = new Timer(1000, 300);

  var i:Number = 300;

public function timerClass() {

   // constructor code

   timerTxt.text = String("05:00");

   myTimer.addEventListener(TimerEvent.TIMER, updateTime);

   myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, TimerComplete);

   startbutton.addEventListener(MouseEvent.CLICK, StartNow);

   pausebutton.addEventListener(MouseEvent.CLICK, PauseNow);

   restartbutton.addEventListener(MouseEvent.CLICK, restartNow);

   }

  private function updateTime(e:TimerEvent):void{

   i--;

   var totalSeconds:* = i;

   var minutes:* = Math.floor(totalSeconds/60);

   var seconds:* = totalSeconds % 60;

   if(String(minutes).length < 2)

    minutes = "0" + minutes;

    if(String(seconds).length < 2)

    seconds = "0" + seconds;

   timerTxt.text = minutes + ":" + seconds;

  }

 

  private function TimerComplete(e:TimerEvent):void{

   messageTxt.text = "PRESENTATION IS NOW OVER"

   timerTxt.text = String("00:00");

  }

  private function StartNow(e:MouseEvent):void{

   myTimer.start();

  }

  private function PauseNow(e:MouseEvent):void{

   myTimer.stop();

 

  }

   private function restartNow(e:MouseEvent):void{

   }

  }

}

TOPICS
ActionScript

Views

398

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 10, 2019 0
Adobe Community Professional ,
Mar 11, 2019

Copy link to clipboard

Copied

Hi.

You need to stop the timer, reset the i variable, reset your text field to the total time, and then start the timer again. For this, your restartNow function could look like this:

private function restartNow(e:MouseEvent): void

{

    myTimer.stop();

    i = 300;

    timerTxt.text = String("05:00");

    myTimer.start();          

}

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2019 0
Community Beginner ,
Mar 11, 2019

Copy link to clipboard

Copied

ok that works great unti the end when it runs down to 00:00 and displays the message txt then it wont restart again

any suggestions

thank you

package  {

import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.ui.Mouse;

public class timerClass extends MovieClip {
  var myTimer:Timer = new Timer(1000, 300);
  var i:Number = 300;
public function timerClass() {
   // constructor code
   timerTxt.text = String("05:00");
   myTimer.addEventListener(TimerEvent.TIMER, updateTime);
   myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, TimerComplete);
   startbutton.addEventListener(MouseEvent.CLICK, StartNow);
   pausebutton.addEventListener(MouseEvent.CLICK, PauseNow);
   restartbutton.addEventListener(MouseEvent.CLICK, restartNow);
   }
  private function updateTime(e:TimerEvent){
   i--;
   var totalSeconds:* = i;
   var minutes:* = Math.floor(totalSeconds/60);
   var seconds:* = totalSeconds % 60;
   if(String(minutes).length < 2)
    minutes = "0" + minutes;
    if(String(seconds).length < 2)
    seconds = "0" + seconds;
   timerTxt.text = minutes + ":" + seconds;
  }
 
  private function TimerComplete(e:TimerEvent){
   messageTxt.text = "PRESENTATION IS NOW OVER"
   timerTxt.text = String("00:00");
  }
  private function StartNow(e:MouseEvent){
   myTimer.start();
 
  }
 
  private function PauseNow(e:MouseEvent){
   myTimer.stop();
  }
 
  private function restartNow(e:MouseEvent): void{ 
        myTimer.stop(); 
        i = 300; 
        timerTxt.text = String("05:00"); 
        myTimer.start();      
  }
}
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2019 0
Adobe Community Professional ,
Mar 11, 2019

Copy link to clipboard

Copied

OK.

Try this:

private function restartNow(e: MouseEvent): void

{

    myTimer.stop();

    myTimer = new Timer(1000, 7);

    myTimer.addEventListener(TimerEvent.TIMER, updateTime);

    myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, TimerComplete);

    i = 7;

    messageTxt.text = ""

    timerTxt.text = String("05:00");

    myTimer.start();           

}

As the code is repeating too much it will be a good idea to wrap some code inside of functions and store some hardcoded values in variables.

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2019 0
Community Beginner ,
Mar 11, 2019

Copy link to clipboard

Copied

that's seems to be running fine now

thank you very much

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2019 1
Adobe Community Professional ,
Mar 11, 2019

Copy link to clipboard

Copied

You're welcome.

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2019 0
Community Beginner ,
Mar 20, 2019

Copy link to clipboard

Copied

I have a countdown timer I am trying to use in a game like second life its works fine in world the trouble is that only the one that presses start button can see the timer countdown

any sugestions

package  {

import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.ui.Mouse;

public class timerClass extends MovieClip {
  var myTimer:Timer = new Timer(1000, 300);
  var i:Number = 300;
public function timerClass() {
   // constructor code
   timerTxt.text = String("05:00");
   myTimer.addEventListener(TimerEvent.TIMER, updateTime);
   myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, TimerComplete);
   startbutton.addEventListener(MouseEvent.CLICK, StartNow);
   pausebutton.addEventListener(MouseEvent.CLICK, PauseNow);
   restartbutton.addEventListener(MouseEvent.CLICK, restartNow);
   }
  private function updateTime(e:TimerEvent){
   i--;
   var totalSeconds:* = i;
   var minutes:* = Math.floor(totalSeconds/60);
   var seconds:* = totalSeconds % 60;
   if(String(minutes).length < 2)
    minutes = "0" + minutes;
    if(String(seconds).length < 2)
    seconds = "0" + seconds;
   timerTxt.text = minutes + ":" + seconds;
  }
 
  private function TimerComplete(e:TimerEvent){
   messageTxt.text = "PRESENTATION IS NOW OVER"
   timerTxt.text = String("00:00");
  }
  private function StartNow(e:MouseEvent){
   myTimer.start();
 
  }
 
  private function PauseNow(e:MouseEvent){
   myTimer.stop();
  }
 
  private function restartNow(e: MouseEvent): void{ 
    myTimer.stop(); 
    myTimer = new Timer(1000, 300); 
    myTimer.addEventListener(TimerEvent.TIMER, updateTime); 
    myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, TimerComplete); 
    i = 300; 
    messageTxt.text = "" 
    timerTxt.text = String("05:00"); 
        
  }
}
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 20, 2019 0