FORUMS: list search recent posts

# Relative _x and _y

FAQ   •   VIEW ALL
 Relative _x and _y on Nov 17, 2006 at 2:41:26 am

Let's say I have the _x and _y or one object, and would like to know what its _x and _y are relative to another object. How do I do this?

 Re: Relative _x and _yby lajoieton Nov 18, 2006 at 12:34:06 am

It should just be simple math:

relativeX = clip1._x - clip2._x;
relativeY = clip1._y - clip2._y;

 Re: Relative _x and _yon Nov 18, 2006 at 1:06:07 am

Not that simple when one of them is contained within a movie clip that is scaled and rotating.

 Re: Relative _x and _yby lajoieton Nov 18, 2006 at 9:23:34 pm

Try the MovieClip.localToGlobal() method.

 Re: Relative _x and _yon Nov 19, 2006 at 5:48:30 pm

In After Effects, there is a function called toWorld(). A layer's location is given relative to its parent. If you use toWorld() then you can get that location relative to the world at large.

I guess I was hoping there was some similar function in Flash to give me the X and Y relative to _root.

 Re: Relative _x and _yby lajoieton Nov 19, 2006 at 11:32:04 pm

Well, you can use the getBounds(_root) method to get the boundaries of an object based on the root timeline. You use it by assigning it to a variable which then gets assigned ".xMin", ".xMax", ".yMin", & ".yMax" values which are the coordinates of the 4 boundary edges of the clip.

 Re: Relative _x and _yon Nov 20, 2006 at 12:51:29 am

Thanks, that would work.

When I looked that up, I also found globalToLocal() and localToGlobal() which are exactly what I was looking for.

 Re: Relative _x and _yby lajoieton Nov 20, 2006 at 12:21:06 pm

wasn't that what I said in the second reply???