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

localX on datagrid giving strange readings

Guest
Jan 30, 2013 Jan 30, 2013

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.

TOPICS
ActionScript
822
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 , Jan 31, 2013 Jan 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 optio

...
Translate
LEGEND ,
Jan 31, 2013 Jan 31, 2013

Show your code.

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
LEGEND ,
Jan 31, 2013 Jan 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

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
Guest
Jan 31, 2013 Jan 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.

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
LEGEND ,
Jan 31, 2013 Jan 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. 

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
Guest
Jan 31, 2013 Jan 31, 2013

Cheers Ned

I opted for the 272 localX = 1100 datagridX, and the coordinates are working now.

Much appreciated mate.

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
Guest
Feb 01, 2013 Feb 01, 2013

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?

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
LEGEND ,
Feb 01, 2013 Feb 01, 2013

Have you checked to see if the mouseX value of the grid itself is the value you are after?

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
Guest
Feb 01, 2013 Feb 01, 2013

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 !!!

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
LEGEND ,
Feb 02, 2013 Feb 02, 2013
LATEST

You're welcome

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