Skip to main content
Participating Frequently
November 2, 2021
Answered

Component variable to allow access to a frame

Hello

 

Trying to create an password to access a frame.

 

I have an Animate component with an instance name of "TextInput_cmpnt".

I also have a custom submit button with an instance name of "submit_btn".

The following code is in the Actions layer:

 

_this.submit_btn.on('click', function(){

_this.myVar = "Name";

function checkPassword(){
if(TextInput_cmpnt.myVar="Paul" ){
_this.gotoAndPlay(4);
}else{
_this.gotoAndPlay(3);
}

}
checkPassword();
});

 

Any ideas on what. am doing wrong here will be much appreciated.

 

 

 

 

 

 

 

    This topic is closed to new replies. Start a new post to keep the conversation going.
    JoãoCésar17023019
    JoãoCésar17023019Correct answer
    Community Expert
    November 3, 2021

    Hi.

     

    There is at least one problem in this line:

     

    if (TextInput_cmpnt.myVar = "Paul")

     

     

    - The equality operators are == or === (triple equals are mostly used in JavaScript);

    - Also, do you have a property called myVar in your TextInput component instance?

     

    Or maybe what you want is something like this?

     

    var _this = this;
    
    _this.submit_btn.on('click', function()
    {
    	if (TextInput_cmpnt.value === "Paul")
    	{
    		_this.gotoAndPlay(4);
    	}
    	else
    	{
    		_this.gotoAndPlay(3);
    	}
    });

     

     

    Please let us know.

     

    Regards,

    JC

     

    3 replies

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    November 3, 2021

    Hi.

     

    There is at least one problem in this line:

     

    if (TextInput_cmpnt.myVar = "Paul")

     

     

    - The equality operators are == or === (triple equals are mostly used in JavaScript);

    - Also, do you have a property called myVar in your TextInput component instance?

     

    Or maybe what you want is something like this?

     

    var _this = this;
    
    _this.submit_btn.on('click', function()
    {
    	if (TextInput_cmpnt.value === "Paul")
    	{
    		_this.gotoAndPlay(4);
    	}
    	else
    	{
    		_this.gotoAndPlay(3);
    	}
    });

     

     

    Please let us know.

     

    Regards,

    JC

     

    Translate
    Participating Frequently
    November 3, 2021

    JoãoCésar, than you very much!

     

    It worked!

     

    Truly appreciate your support.

     

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    November 3, 2021

    Amazing! You're welcome!

    Translate