views:

117

answers:

2

I know about Flash's localToGlobal and globalToLocal methods to transform coordinates from the local system to the global system, but is there a way to achieve the intermediate? To transform coordinates from an arbitrary system to any other arbitrary system?

I have a clickable object inside a Sprite, and the Sprite is a child of the stage. I want to retrieve the clicked point in the Sprite.

+3  A: 

While typing I came up with the answer. I figured I'd post the question anyway so that others may find it by search.

bCoordinate = b.globalToLocal(a.localToGlobal(localPoint));
Bart van Heukelom
+1  A: 

you can use the following:

var m:Matrix = a.transform.matrix.clone();
m.invert();
bCoord = m.transformPoint(aCoord);

looks a little verbous, due to the really stupid signature of invert, but when clips are nested deeply, it should be faster.

sorry, just reread your question. if you only want to find out the clicked point, then you can do globalToLocal with the MouseEvent's stageX and stageY.

greetz
back2dos

back2dos
Isn't the transform matrix only relative to the parent though?
Bart van Heukelom
@Bart van Heukelom: correct. It seemed though, you wanted only that.
back2dos
Ah yes, of course, you're right. It would allow me to fix this specific problem. You can't use it to go between arbitrary coordinate spaces however.
Bart van Heukelom