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

setTIMEout Canvas HTML NEED HELP

Community Beginner ,
May 20, 2020 May 20, 2020

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");
}
}

 

972
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 20, 2020 May 20, 2020

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
...
Translate
Community Expert ,
May 20, 2020 May 20, 2020

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

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 Beginner ,
May 20, 2020 May 20, 2020

Thank you verry much works fine !

 

if i want it get off without reset time ?

thanks for help

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 20, 2020 May 20, 2020
LATEST

You're welcome!

 

And you can just click again and the target Movie Clip instance will go back to the "off" label.

 

 

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