Skip to main content
Jeffery.Wright
Inspiring
November 22, 2021
Answered

Canvas Uncaught TypeError: Parent object's X and Y cannot = This object's X and Y?

  • November 22, 2021
  • 1 reply
  • 911 views

When a button object is clicked I want a marker to appear over it to identify that is the one that was clicked. This works fine when both objects are in the same MC, but doesn't if they're not.

Why not? 

 

this.button_01.on("click", function () {  
f_01();
this.parent.MARKER.x = this.button_01.x;
this.parent.MARKER.y = this.button_01.y;	
	});


Uncaught TypeError: Cannot read properties of undefined (reading 'x')

 

this.button_01.x; looks well defined, to me. 

Any suggestions to make this happen? Thanks!

 

This topic has been closed for replies.
Correct answer Jeffery.Wright

Colin,

 

I got it sorted... apparently this involves Scope... a concept I have yet to understand. This is the code inside my MC that refers to the Marker in its parent; timeline root:

 

var _this = this

this.button_01.on("click", function () {  
f_01();
exportRoot.MARKER.x = _this.button_01.x;
exportRoot.MARKER.y = _this.button_01.y;	
	});

 

This makes it possible to use one parent Marker object to highlight as selected/clicked, any clickable object in multiple MC's - these MC's are buttons grouped by category which must have their visibility switchable as a kind of filter toggle. I appreciate your helping me tackle this challenge. 

 

1 reply

Colin Holgate
Inspiring
November 22, 2021

There are local to global, global to local, and local to local functions. I've never used local to local, but that may be the one that will help:

https://createjs.com/tutorials/HitTest/

Jeffery.Wright
Inspiring
November 22, 2021

Thanks, Colin, that is an interesting article. 

 

For my case, I'm not in need of any sort of hit test, I simply want the parent object's x and y to become the same value as the x and y of the object within the MC.

 

Thanks again!

Colin Holgate
Inspiring
November 22, 2021

HitTest was just that particular example. The local to local may still be important.