It’s simple: Whenever you do coordinate conversions, you do one, then you do the other. Rarely are you just trying to convert to _level0 stage or from _level0 to a clip. It’s 99.9% a movieclip to a movieclip conversion! And when you do that, you use both globalToLocal and localToGlobal.
I came up with localToLocal way back in Flash6 and realized that I still use it to this day and coordinate conversion was never so easy. Works every time and I can pass original x/y values if I want to (IE: mouse coordinates to be converted). I had this posted on an old site a while back and thought I’d put it out here for archive sake.
[as]class com.rockonflash.utils.CoordinateTools
{
public static function localToLocal(from:MovieClip, to:MovieClip, origin:Object):Object
{
var point:Object = origin == undefined ? {x: 0, y: 0} : origin;
from.localToGlobal(point);
to.globalToLocal(point);
return point;
}
}[/as]
Just use it to create your point object and you’re done:
var point:Object = CoordinateTools.localToLocal(from:MovieClip, to:MovieClip); trace(point.x + " : " + point.y)
I’ll be putting out the AS3 version as soon as i have time to test it


November 12, 2006 at 9:10 pm
So simple… so nice…
Thanx!
November 13, 2006 at 10:12 pm
[...] John Grden came up with great idea to deal with coordinate conversion in Flash – localToLocal! He first implemented it way back in Flash6. [...]
November 26, 2006 at 7:31 am
Very nice.
Something I’ve been doing since Flash 8 is using the new flash.geom.Point class instead of the generic Object class for the point object. I guess it doesn’t really matter, but when doing my class editing in Eclipse, I get warnings with the x and y properties in Object. It doesn’t screw anything up, but it’s annoying. Using the Point class which has x and y properties, it works out great. And it seems more intuitive too. It is a point.
November 26, 2006 at 7:42 am
yeah, that’s a great point, problem is flash package is Flash8 only ;(
I suppose I could return some sort of proprietary data object, but then I think that might defeat the purpose of “ease of use”
May 16, 2007 at 12:20 am
Any luck with the AS3 version?
May 16, 2007 at 1:52 am
[...] I had said I’d post the AS3 version of localToLocal and here it is! I’ll be adding some modifications for Flex2 stuff as I get more familiar with it, but this works as it did with AS2. I’ve tested with Flex2 and basic AS3 apps and works very well. [...]
November 2, 2007 at 9:27 pm
Awesome so glad I found this! Thank you John!
September 19, 2008 at 7:51 pm
Here’s how to do it in AS3:
function localToLocal(fr:MovieClip, to:MovieClip):Point {
return to.globalToLocal(fr.localToGlobal(new Point()));
};
August 10, 2009 at 2:54 pm
thanx js, that was exactly what i was looking for ;D