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

setTIMEout Canvas HTML NEED HELP

Community Beginner ,
May 20, 2020 May 20, 2020

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

 

Views

843

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

Votes

Translate

Translate
Community Expert ,
May 20, 2020 May 20, 2020

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

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

Copy link to clipboard

Copied

Thank you verry much works fine !

 

if i want it get off without reset time ?

thanks for help

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

Copy link to clipboard

Copied

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

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