Skip to main content
Inspiring
February 25, 2021
Answered

button symbol to make mcs visible one by one

  • February 25, 2021
  • 1 reply
  • 307 views

Hi.

I have four movieclips sb1, sb2, sb3, sb4.

They all start off visible=false.

When I run my code upon clicking the btn it doesn't work.

I would appreciate any help.

Cheers.

Basically it's a sentence that I reveal word for word.

My    dog      is      driving.

this.sb1.visible =false;
this.sb2.visible =false;
this.sb3.visible =false;
this.sb4.visible =false;


btn_integer = 0;


this.btn.addEventListener("click", clickHandler.bind(this));

function clickHandler(event) 
{
  btn_integer = btn_integer + 1;
	If (btn_integer = 1) 
	{
		this.sb1.visible = true;
	} 
	If (btn_integer = 2)  
	{
		this.sb2.visible=true;
	}
	If (btn_integer = 3)  
	{
		this.sb3.visible=true;
	}
	If (btn_integer = 4)  
	{
		this.sb4.visible=true;
	}
}

 

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

    Hi.

     

    There are 2 errors:

     

    - The if  keyword must be in lowercase (if);

    - And you're using assignment operators (=) instead of equality operators (==).

     

    Also, use else if to make your code more efficient.

     

    It should be like this:

     

     

     

    this.sb1.visible = false;
    this.sb2.visible = false;
    this.sb3.visible = false;
    this.sb4.visible = false;
    
    btn_integer = 0; // you're declaring a global variable here. Is this what you really want? If not, use the var keyword. E.g.: var btn_integer = 0;
    
    this.btn.addEventListener("click", clickHandler.bind(this));
    
    function clickHandler(event) 
    {
    	btn_integer = btn_integer + 1;
    		
    	if (btn_integer == 1) 
    	{
    		this.sb1.visible = true;
    	} 
    	else if (btn_integer == 2)  
    	{
    		this.sb2.visible = true;
    	}
    	else if (btn_integer == 3)  
    	{
    		this.sb3.visible = true;
    	}
    	else if (btn_integer == 4)  
    	{
    		this.sb4.visible = true;
    	}
    }

     

     

     

     

    Regards,

    JC

    1 reply

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    February 25, 2021

    Hi.

     

    There are 2 errors:

     

    - The if  keyword must be in lowercase (if);

    - And you're using assignment operators (=) instead of equality operators (==).

     

    Also, use else if to make your code more efficient.

     

    It should be like this:

     

     

     

    this.sb1.visible = false;
    this.sb2.visible = false;
    this.sb3.visible = false;
    this.sb4.visible = false;
    
    btn_integer = 0; // you're declaring a global variable here. Is this what you really want? If not, use the var keyword. E.g.: var btn_integer = 0;
    
    this.btn.addEventListener("click", clickHandler.bind(this));
    
    function clickHandler(event) 
    {
    	btn_integer = btn_integer + 1;
    		
    	if (btn_integer == 1) 
    	{
    		this.sb1.visible = true;
    	} 
    	else if (btn_integer == 2)  
    	{
    		this.sb2.visible = true;
    	}
    	else if (btn_integer == 3)  
    	{
    		this.sb3.visible = true;
    	}
    	else if (btn_integer == 4)  
    	{
    		this.sb4.visible = true;
    	}
    }

     

     

     

     

    Regards,

    JC

    Inspiring
    February 25, 2021

    THANK YOU so much.

    I haven't written code for so many years and it's different in javascript but yes, I forgot the lowercase in the if statements and the == operator etc...

    BUT I did change my code to else if, HOWEVER, I couldn't EDIT my post. Where is the edit button?