0
votes

Im getting a weird result with local to global which for the last 2 hours has nearly made me cry.

I'm trying to get the x of a child, of a child object, and it's coming back with strange minus numbers, where it should be a healthy positive number on the other side of the screen!

so I've got childObject in childContainer, and no variation of

 localToGlobal(new Point(childContainer.childObject.x,0)).x;
   or childContainer.childObject.localToGlobal(new Point(0,0)).x;
or childContainer.localToGlobal(new Point(childObject.x,0)).x;

Or anything similar is giving me a result I can use (i.m expecting something like 1100, and I'm getting -91);

I've tried taking this result away from the stageWidth, and it's close, but not really right.

Please help!

2
I don't think this is enough information for a good answer. We can only guess why the coordinates are not what you expect. Can you post more code that includes the containers in question?Aaron Beall

2 Answers

1
votes

localToGlobal converts the Point you pass in to stage coordinates using the display object that you call localToGlobal on.

So if you call it like below it will return the stage coordinates of the child object.

childObject.localToGlobal(new Point(0, 0));
0
votes

Thanks.

The problem was timing. This was getting called before the parent had been added to the stage. School boy error.