Copy link to clipboard
Copied
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.
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 optio
...Copy link to clipboard
Copied
Show your code.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Ahh - so the datagrid comes with a default w and h of 272 & 191.
Thanks Ned - I'll have a play with that tonight.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Cheers Ned
I opted for the 272 localX = 1100 datagridX, and the coordinates are working now.
Much appreciated mate.
Copy link to clipboard
Copied
I think I spoke too soon. When I was testing this, I didn't have any data in n the datagrid. Now I do, and the coordinates seem to be taken from each column, as opposed to the datagrid. This happens for both localX and mouseX.
To further explain, if I click halfway across column 2, the trace for X is euql to halfway across the DG. If I click 3/4 of the way through column 1, the trace for X is equal to 3/4 the way across the datagrid.
Since my datagrid is a static size, would I be better off setting up a stage mouse listener (each time the window with the datagrid is opened), and taking my x/y coords from that?
Copy link to clipboard
Copied
Have you checked to see if the mouseX value of the grid itself is the value you are after?
Copy link to clipboard
Copied
Well that's bizarre - yeah I did try it after you mentioned it in an earlier post, and could have sworn is wasn't working, but it is now. I must have had something wrong in there.
Thanks Ned !!!
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now