Copy link to clipboard
Copied
Cannot read property 'b_Title' of undefined ... yet it is indeed defined.
This is the offending code:
this.p_Button.addEventListener("click", APDHMIDM.bind(this)); // error-free
function b_Lang(){
if( IsRussia == 1){
this.p_Button.b_Title.text = ru_APDHMIDM;
}
else{
this.p_Button.b_Title.text = en_APDHMIDM;
}
}
b_Lang();
I am differentiating between two languages for a button label to display. This is the code I have been using all along with Zero issues:
this.p_Button.addEventListener("click", APDHMIDM.bind(this));
this.p_Button.b_Title.text = en_APDHMIDM;
So, if property 'b_Title' is defined there, why isn't it in a simple else if function?
Ideas, anyone? Thanks.
I think this is a problem with scope.
I would use
var _this = this
and then use
function b_Lang(){
if( IsRussia == 1){
_this.p_Button.b_Title.text = ru_APDHMIDM;
}
else{
_this.p_Button.b_Title.text = en_APDHMIDM;
}
}
b_Lang();
Copy link to clipboard
Copied
I think this is a problem with scope.
I would use
var _this = this
and then use
function b_Lang(){
if( IsRussia == 1){
_this.p_Button.b_Title.text = ru_APDHMIDM;
}
else{
_this.p_Button.b_Title.text = en_APDHMIDM;
}
}
b_Lang();
Copy link to clipboard
Copied
These are the sort of things that completely baffle people like me, it does my head in.
Why var _this = this when you could simply use this in the first place, as I did?
How did that change any scope when this = the same things as var _this = this?
The value for _this is this, which is what I used in the first place, what does making it the value of a variable do exactly? And how would anyone know to to that? It's black magic.
Thank you, your suggestion is the solution, I appreciate it.