Highlighted

setTimeout not working in Animate HTML5 Canvas

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

.

.

.

}

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

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

Views

835

Likes

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

setTimeout not working in Animate HTML5 Canvas

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

.

.

.

}

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

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

Views

836

Likes

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
May 17, 2019 0
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
May 17, 2019 1
Explorer ,
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.

Likes

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
Reply
Loading...
May 17, 2019 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
May 17, 2019 0
Explorer ,
May 29, 2019

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
May 29, 2019 0
Adobe Community Professional ,
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

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
May 17, 2019 0
Explorer ,
May 17, 2019

Copy link to clipboard

Copied

Oh thank you for this!

Likes

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
Reply
Loading...
May 17, 2019 1