Skip to main content
paulam7245803
Participant
July 29, 2019
Answered

How to create a timer (chronometer) in Adobe Animate

  • July 29, 2019
  • 2 replies
  • 4314 views

Hello!

I am learning how to use Animate and I need to create a timer, like a chronometer that shows minutes and seconds on display.

Also, I need to include buttons to start, pause and reset the timer. I am trying to create them by myself but, unfortunately they don't appear on screen once I enter javascript codes (a coding error perhaps?). I tried to amend this as well but I couldn't find any relevant tutorial video.

I look forward to your answer.

Thank you!

This topic has been closed for replies.
Correct answer Nick Gioia

see if this code helps.

var book_release_date = new Date(2019,6,1);  // for july, not june, 1st 2019 release date.

createjs.Ticker.addEventListener('tick',tickF.bind(this))

function tickF(e){

this.tf.text = formatF(book_release_date.getTime()-new Date().getTime());

}

function formatF(ms){

var days = Math.floor(ms/(1000*60*60*24));

ms -= days*1000*60*60*24;

var hours = Math.floor(ms/(1000*60*60));

ms -= hours*1000*60*60

var min = Math.floor(ms/(1000*60));

ms -= min*1000*60;

var sec = Math.floor(ms/1000);

return ' '+padF(days)+'  '+padF(hours)+'  '+padF(min)+'  '+padF(sec);

}

function padF(n){

var s=n.toString();

while(s.length<2){

s='0'+s;

}

return s;

}

2 replies

Nick GioiaCommunity ExpertCorrect answer
Community Expert
July 29, 2019

see if this code helps.

var book_release_date = new Date(2019,6,1);  // for july, not june, 1st 2019 release date.

createjs.Ticker.addEventListener('tick',tickF.bind(this))

function tickF(e){

this.tf.text = formatF(book_release_date.getTime()-new Date().getTime());

}

function formatF(ms){

var days = Math.floor(ms/(1000*60*60*24));

ms -= days*1000*60*60*24;

var hours = Math.floor(ms/(1000*60*60));

ms -= hours*1000*60*60

var min = Math.floor(ms/(1000*60));

ms -= min*1000*60;

var sec = Math.floor(ms/1000);

return ' '+padF(days)+'  '+padF(hours)+'  '+padF(min)+'  '+padF(sec);

}

function padF(n){

var s=n.toString();

while(s.length<2){

s='0'+s;

}

return s;

}

JoãoCésar17023019
Community Expert
Community Expert
July 29, 2019

Hi.

This answer might be what you need.

Countdown Timer with canvas

Regards,

JC