• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Canvas time counter to specific time

Community Beginner ,
Feb 19, 2024 Feb 19, 2024

Copy link to clipboard

Copied

Hi, 

I found this js code and now I need to use it in an Adobe Animate. If it is possible? If so, I would like to put the counter in an animated dynamic text box. 

<script>
// Set the date we're counting down to
var countDownDate = new Date("February 28, 24 21:35:00").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

// Get today's date and time
var now = new Date().getTime();

// Find the distance between now and the count down date
var distance = countDownDate - now;

// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);

// Display the result in the element with id="demo"
document.getElementById("demo").innerHTML = hours + " godzin, "
+ minutes + " minut, " + seconds + " sekund ";

// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "End";
}
}, 1000);
</script>

Views

128

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
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 20, 2024 Feb 20, 2024

Hi.

 

You just need to use a dynamic text field instance on stage instead of a DOM element to display the calculated time. Like this:

var root = this;

// Set the date we're counting down to
var countDownDate = new Date("February 28, 24 21:35:00").getTime();

// Update the count down every 1 second
var x = setInterval(function()
{
	// Get today's date and time
	var now = new Date().getTime();
	
	// Find the distance between now and the count down date
	var distance = countDownDate - now;
	
	// T
...

Votes

Translate

Translate
Community Expert ,
Feb 20, 2024 Feb 20, 2024

Copy link to clipboard

Copied

Hi.

 

You just need to use a dynamic text field instance on stage instead of a DOM element to display the calculated time. Like this:

var root = this;

// Set the date we're counting down to
var countDownDate = new Date("February 28, 24 21:35:00").getTime();

// Update the count down every 1 second
var x = setInterval(function()
{
	// Get today's date and time
	var now = new Date().getTime();
	
	// Find the distance between now and the count down date
	var distance = countDownDate - now;
	
	// Time calculations for days, hours, minutes and seconds
	var days = Math.floor(distance / (1000 * 60 * 60 * 24));
	var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
	var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
	var seconds = Math.floor((distance % (1000 * 60)) / 1000);
	
	// Display the result in the element with id="demo"
	root.yourTF.text = hours + " godzin, " // CHANGE HERE
	+ minutes + " minut, " + seconds + " sekund ";
	
	// If the count down is finished, write some text
	if (distance < 0)
	{
		clearInterval(x);
		root.yourTF.text = "End"; // CHANGE HERE
	}
}, 1000);

 

Regards,

JC

Votes

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
community guidelines
Community Beginner ,
Feb 20, 2024 Feb 20, 2024

Copy link to clipboard

Copied

LATEST

You saved my ass... Thank you very much for your quick response!!!

Votes

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
community guidelines