PDA

View Full Version : Getting a child's real coordinates



substance
May 15th, 2008, 01:16 AM
When trying to get coordinates from a child object through it's parent, the results are in relation to it's parent. But what if I wanted these coordinates in relation to the stage?

ajcates
May 15th, 2008, 02:48 AM
http://www.kirupa.com/forum/showthread.php?p=2167721#post2167721

You thinking backwards. you need to redesign your code, so you can look from the outside in not the other way around.

substance
May 15th, 2008, 03:16 AM
Maybe my exmaple was misleading...

In my case I am "looking from the outside in". In my document class (stage) I'm trying to get properties from a child's child. I understand senocular's post but it doesnt really relate to what im doing.

ajcates
May 15th, 2008, 03:21 AM
stage.childsName.otherChild.x

Why can't you use that then?

substance
May 15th, 2008, 03:35 AM
stage.childsName.otherChild.x

Why can't you use that then?

I can, but that will give me "otherChild"'s x position in relation to "childsName". For example if I did:


stage.addChild(Dad);
Dad.x = 100;
Dad.y = 100;
Dad.addChild(son);
trace (Dad.son.x);

It would return 0 even though it's position will technically be 100.

doridori
May 15th, 2008, 03:58 AM
You can use localToGlobal().

I'm not sure how it works exactly so you better check it out yourself.
Search the Flash Help.

amarghosh
May 15th, 2008, 04:13 AM
DisplayObject has a localToGlobal (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html#localToGlobal()) method;

Felixz
May 15th, 2008, 07:42 AM
root.addChild(Dad);
Dad.x = 100;
Dad.y = 100;
Dad.addChild(son);
var point:Point=new Point(son.x,son.y);
trace (Dad.localToGlobal(point));

ajcates
May 15th, 2008, 12:04 PM
if you need to do that, then that child needs to be in the stage, not on that movieclip.

Felixz
May 15th, 2008, 12:45 PM
if you need to do that, then that child needs to be in the stage, not on that movieclip.
What u mean by that?
I used this for finding stage boundaries and it's working perfectly on every clip which hes reference to stage

substance
May 15th, 2008, 01:41 PM
Thanks all, that's what I was looking for.

JBPresents
May 15th, 2008, 08:25 PM
woah nice
i like that


root.addChild(Dad);
Dad.x = 100;
Dad.y = 100;
Dad.addChild(son);
var point:Point=new Point(son.x,son.y);
trace (Dad.localToGlobal(point));