localToGlobal allows you to get the actual position of a movie clip, that is inside another movieclip.
Normally, if you trace, or try to get, the x or y coordinate of a movie clip, you will get its position, relative to the 0,0 coordinates of the movie clip it is sitting in. These are the local coordinates of the child movieclip.
To get the global coordinates, ie, where it REALLY is on the main stage, you need points, and the localToGlobal function.
e.g
(On the stage, there is a squareHole_mc, and inside that is a roundPeg_mc.)
var pt:Point = new Point(squareHole_mc.roundPeg_mc.x,squareHole_mc.roundPeg_mc.y);
pt = squareHole.localToGlobal(pt);
So basically, you create a Point, that contains the local x and y coordinates you are interested in. Then you use localToGlobal to find out the global version of those coordinates, bearing in mind they are sitting in a parent movieclip.
UPDATE:
Now in one line(!!!):
var pt:Point = sqH.localToGlobal(new Point(sqH.rPeg.x,sqH.rPeg.y));
No comments:
Post a Comment
Please enter your message here...