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.
I included the entire class here, use it as you will – Rock on \m/
[as]/*
Copyright (c) 2007 John Grden
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the “Software”), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package com.rockonflash.utils
{
import flash.display.Sprite;
import flash.geom.Point;
public class CoordinateTools
{
public static function localToLocal(containerFrom:DisplayObject, containerTo:DisplayObject, origin:Point=null):Point
{
var point:Point = origin ? origin : new Point();
point = containerFrom.localToGlobal(point);
point = containerTo.globalToLocal(point);
return point;
}
}
}[/as]



May 17, 2007 at 2:15 pm
nice ‘n handy.. hey that sounds like a detergent…
September 3, 2007 at 9:38 am
[...] Persze package-ben az igazi: http://www.rockonflash.com/blog/?p=49 Azért vicces, hogy még copyright is van [...]
September 10, 2007 at 3:11 am
I added an origin:Point argument to pass through incase you were converting mouse coordinates
November 23, 2008 at 1:50 pm
Hey John
Is this any use to you. It’s a hacky version of your localToLocal with a method for 3D added (local3DToLocal3D) – I needed one myself. I took out the origin Point because it wasn’t relevant to my needs – but I hope it will be of some use to you. Thank you very much for your original and very useful work on localToLocal, it got me out of the crap a few times.
You’ve probably already done this, so sorry if it’s old news:
/*
Copyright (c) 2007 John Grden
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the “Software”), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package com.rockonflash.utils{
import flash.display.*;
import flash.geom.*;
public class CoordinateTools {
public static function localToLocal(containerFrom:DisplayObject, containerTo:DisplayObject, origin:Point=null):Point {
var point:Point = origin ? origin : new Point();
point=containerFrom.localToGlobal(point);
point=containerTo.globalToLocal(point);
return point;
}
public static function local3DToLocal3D(containerFrom:DisplayObject, containerTo:DisplayObject):Vector3D {
var vector3D:Vector3D = containerFrom.transform.matrix3D.decompose()[0];
var point:Point = new Point()
point=containerTo.local3DToGlobal(vector3D);
vector3D=containerFrom.globalToLocal3D(point);
return vector3D;
}
}
}
September 17, 2009 at 1:31 pm
[...] …and Grden’s localToLocal function [...]
September 20, 2009 at 6:45 pm
Thanks, this function helped solve my confused coordinates.