Skip to main content
January 31, 2013
Answered

localX on datagrid giving strange readings

  • January 31, 2013
  • 2 replies
  • 877 views

Hi

I have a datagrid that is 1100 wide/

I've set up a RIGHT_CLICK listener on it, and am tracing the x/y coords with localX and localY.

Clicking at x=0 traces x at being zero, but if I click to the very right on the datagrid, around the x= 1100 mark, it traces x as being around 280.  And clicking halfway traces x at 140 (it should be around 550).

Same sort of thing is happening on the y axis.

What is this an indication of that I am doing wrong?

Cheers guys.

This topic has been closed for replies.
Correct answer Ned Murphy

The numbers you are seeing are relative to the background of the datagrid, which is 272 pixels wide (191 high).  When you resize the datagrid the background is stretched, not resized, so its reported x positions remain the same.

The event you are reading is picking up the background as the target, so it is giving you the localX value relative to the target. 

If you want to use the localX you could use it as defining a ratio of the datagrid width.... 272 localX = 1100 datagridX.   As another option you could physically edit the datagrid background to be 1100 pixels wide which would then give you the localX value relative to the 1100 pixels directly.

An alternative would be to use the DataGrid.mouseX value

2 replies

Ned Murphy
Ned MurphyCorrect answer
Legend
January 31, 2013

The numbers you are seeing are relative to the background of the datagrid, which is 272 pixels wide (191 high).  When you resize the datagrid the background is stretched, not resized, so its reported x positions remain the same.

The event you are reading is picking up the background as the target, so it is giving you the localX value relative to the target. 

If you want to use the localX you could use it as defining a ratio of the datagrid width.... 272 localX = 1100 datagridX.   As another option you could physically edit the datagrid background to be 1100 pixels wide which would then give you the localX value relative to the 1100 pixels directly.

An alternative would be to use the DataGrid.mouseX value

January 31, 2013

Ahh - so the datagrid comes with a default w and h of 272 & 191.

Thanks Ned - I'll have a play with that tonight.

Ned Murphy
Legend
January 31, 2013

Not the datagrid, just its background.  The default size for the datagrid is normally 100x100... but again, if you were to use it at the default size like you are you would stll see the values you see now because the background remains at 272x191. 

Ned Murphy
Legend
January 31, 2013

Show your code.