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

setTimeout not working in Animate HTML5 Canvas

Explorer ,
May 17, 2019 May 17, 2019

Hello everyone,

I am trying to use the setTimeout event in order to delay the firing of a specific function on the click of a button. This is my code, and it is simply not working. The function "playgame" is firing instantly when the button is clicked, instead of waiting the delay. What is my error? Thanks in advance! (This code and all objects are inside frame1 of my Animate timeline.)

this.stop();

setTimeout(playgame,10000);

this.Startbutton.addEventListener("click", ColorsIn.bind(this));

function ColorsIn() {

....(various other tasks that I want to execute before "playgame" function...)

playgame();

}

function playgame(){

.

.

.

}

3.0K
Translate
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 , May 17, 2019 May 17, 2019

Hi.

That's nice you made it work using the mentioned framework.

For future reference, your code could have been written like this:

function ColorsIn()

{

    setTimeout(playgame, 10000);

}

function playgame()

{

    console.log("game started");

}

this.stop();

this.Startbutton.addEventListener("click", ColorsIn.bind(this));

Regards,

JC

Translate
LEGEND ,
May 17, 2019 May 17, 2019

You seem to have a very confused notion of what setTimeout actually does. I recommend reading the documentation for it.

WindowOrWorkerGlobalScope.setTimeout() - Web APIs | MDN

Translate
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
Explorer ,
May 17, 2019 May 17, 2019

Thank you for the resource!

I was able to achieve what I wanted to using the ZIM framework and ZIM library (zimjs.com). The ZIM "timeout" (ZIM Documentation ) function was actually exactly what I was trying to achieve, in my confusion, with the "setTimeout" function.

Translate
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
LEGEND ,
May 17, 2019 May 17, 2019

Please tell us that you didn't import the entire ZIM library for the sole purpose of accomplishing something so completely trivial.

Translate
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
Explorer ,
May 29, 2019 May 29, 2019
LATEST

I have been incorporating many ZIM events, functions, and objects into Animate HTML5 canvas

Translate
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 Expert ,
May 17, 2019 May 17, 2019

Hi.

That's nice you made it work using the mentioned framework.

For future reference, your code could have been written like this:

function ColorsIn()

{

    setTimeout(playgame, 10000);

}

function playgame()

{

    console.log("game started");

}

this.stop();

this.Startbutton.addEventListener("click", ColorsIn.bind(this));

Regards,

JC

Translate
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
Explorer ,
May 17, 2019 May 17, 2019

Oh thank you for this!

Translate
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