Skip to main content
Lbhmus17424462
Participating Frequently
May 20, 2020
Answered

setTIMEout Canvas HTML NEED HELP

  • May 20, 2020
  • 1 reply
  • 1061 views

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

 

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    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

    1 reply

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    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

    Lbhmus17424462
    Participating Frequently
    May 20, 2020

    Thank you verry much works fine !

     

    if i want it get off without reset time ?

    thanks for help

    JoãoCésar17023019
    Community Expert
    Community Expert
    May 21, 2020

    You're welcome!

     

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

     

     

    Regards,

    JC