Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo

Countdown timer with user input

flash as3

  • Please log in to reply
3 replies to this topic

#1 drev

drev

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 04 March 2015 - 01:41 AM

Hello everyone,

 

Please i need assistance with this timer.it has an input bar where you input the time and then the countdown bar but i have not been able to snyc both of them together so that when the timer gets to the set time it does something or stop.

 

please i need your assistance in syncing both together so that when it gets to the desired time it stops or does something.find the fla attached.

 

thanks.

 

this is the code below;

 

stop();
 
var SelectedTime:int = Number(Time_txt.text);
var timer:Timer = new Timer(1000, SelectedTime);
Start_btn.addEventListener(MouseEvent.CLICK, StartTimer);
timer.addEventListener(TimerEvent.TIMER, countdown);
 
function StartTimer(e:MouseEvent):void {
timer.start();
trace(SelectedTime);
}
function countdown(event:TimerEvent) {
var totalSecondsLeft:Number = SelectedTime + timer.currentCount;
trace(timer.currentCount);
if (Number(Time_txt.text) == totalSecondsLeft - 1) {
timer.stop();
} else {
myText.text = timeFormat(totalSecondsLeft);
}
}
function timeFormat(seconds:Number):String {
var hours:int;
var minutes:int;
//var seconds:int;
var sHours:String;
var sMinutes:String;
var sSeconds:String;
if (seconds > 59) {
minutes = Math.floor(seconds / 60 );
sMinutes = String(minutes);
sSeconds = String(seconds % 60);
if (minutes > 59) {
hours = Math.floor(minutes / 60);
sHours = String(hours);
sMinutes = String(minutes % 60);
}
 
if (minutes > 59) {
hours = Math.floor(minutes / 60);
sHours = String(hours);
sMinutes = String(minutes % 60);
}
 
else {
sHours = String(hours);
sMinutes = String(minutes);
sSeconds = String(seconds);
}
if (sSeconds.length == 1) {
sSeconds = "0" + sSeconds;
}
 
if (sMinutes.length == 1) {
sMinutes = "0" + sMinutes;
}
 
if (sHours.length == 1) {
sHours = "0" + sHours;
}
 
return sHours + ":" + sMinutes + ":" + sSeconds;
}
 

please find attached the fla in the zip.

 

thanks

Attached Files


  • 0

#2 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 10 March 2015 - 06:06 PM

Welcome aboard,

 

I am not sure I follow. Are you saying you want to restart the timer when you change a value in the textbox?


  • 0

#3 drev

drev

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 11 March 2015 - 12:11 AM

Hi Black rabbit,

 

Its actually a countdown timer that is supposed to kick off when the user inputes his/her time in the input text box then hits on the enter button.the time then countsndown to the specific time the user put then stop or does something else.

 

My challenge is that the countdown timer does not sync or recognize what the user put in the unput textbox so that the event attached to the specific inputed time can be triggered.i.e if i put  04:02 (four minutes two seconds) in the input text box, when i click start it should countdown to that 04:02 then stop or do something but instead of getting to that time it just continues to count e.g for seconds it doesnt stop at 60 it continues like,...59, 60, 61, 62 etc.you can run the code and see. I hope its clear.

 

thanks


  • 0

#4 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 14 March 2015 - 12:07 AM

I see, that's why you aren't managing the timer or clearing the time interval.

 

This is an awesome tutorial on how to work it out.


  • 0





Also tagged with one or more of these keywords: flash as3

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download