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, (Disj), all I need is make ( prise) get "off " after 60 seconds , and in the seconde click make the time reset
sorry for my english
This is my code
this.Disj.addEventListener("click",switchF.bind(this));
function switchF(e){
if(this.Disj.currentLabel == "up"){
this.Prise.gotoAndStop("on");
} else {
this.Prise.gotoAndStop("off");
}
}
1 Correct answer
Hi.
I think the easiest way would be to extend the "on" label for 60 seconds and just use gotoAndStop to swtich frames.
But if you really need to do it by code, you can check for the Prise instance currentLabel property and use setInterval and clearInterval like this:
function togglePrise(e)
{
clearInterval(this.interval);
if (this.Prise.currentLabel === "off")
{
this.interval = setInterval(function(context)
{
context.Prise.gotoAndStop("off");
}, 60000, this);
this.Prise.g
...
Copy link to clipboard
Copied
Hi.
I think the easiest way would be to extend the "on" label for 60 seconds and just use gotoAndStop to swtich frames.
But if you really need to do it by code, you can check for the Prise instance currentLabel property and use setInterval and clearInterval like this:
function togglePrise(e)
{
clearInterval(this.interval);
if (this.Prise.currentLabel === "off")
{
this.interval = setInterval(function(context)
{
context.Prise.gotoAndStop("off");
}, 60000, this);
this.Prise.gotoAndStop("on");
}
else if (this.Prise.currentLabel === "on")
this.Prise.gotoAndStop("off");
}
this.Disj.on("click", togglePrise.bind(this));
Please let us know if you have any further questions.
Regards,
JC
Copy link to clipboard
Copied
Thank you verry much works fine !
if i want it get off without reset time ?
thanks for help
Copy link to clipboard
Copied
You're welcome!
And you can just click again and the target Movie Clip instance will go back to the "off" label.
Regards,
JC

