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(){
.
.
.
}
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
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.
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.
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.
Copy link to clipboard
Copied
I have been incorporating many ZIM events, functions, and objects into Animate HTML5 canvas
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
Copy link to clipboard
Copied
Oh thank you for this!