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

Defined things, not defined again... HTML5 Canvas

Engaged ,
Apr 29, 2021 Apr 29, 2021

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. 

430
Translate
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

LEGEND , Apr 29, 2021 Apr 29, 2021

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();

 

 

Translate
LEGEND ,
Apr 29, 2021 Apr 29, 2021

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();

 

 

Translate
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
Engaged ,
Apr 29, 2021 Apr 29, 2021
LATEST

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. 

 

 

Translate
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