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

setTimeout not working in Animate HTML5 Canvas

Explorer ,
May 17, 2019 May 17, 2019

Copy link to clipboard

Copied

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(){

.

.

.

}

Views

2.6K

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 , 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

Votes

Translate

Translate
LEGEND ,
May 17, 2019 May 17, 2019

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

LATEST

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

Oh thank you for this!

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