Local to global

snipped by d_wright66

Local to global is very useful when trying to position a movieclip that is on the stage (_root) to a movieclip which is inside another movieclip.

This code moves the movieclip box_mc (global position) which is on the main stage to the position of clip1_mc (the local position) which is inside a movieclip called main_mc. I have found local to global positioning is very useful when developing games.

var myPoint:Object = new Object();
myPoint.x = main_mc.clip1_mc._x;
myPoint.y = main_mc.clip1_mc._y;
trace("x: "+ myPoint.x);
trace("y: "+ myPoint.y);
 
main_mc.localToGlobal(myPoint);
 
box_mc._x = myPoint.x;
box_mc._y = myPoint.y;

The code below is similar to the one above however the movieclip we are trying to position is 2 levels deep within a movieclip instead of the 1 level deep as above. It took me a long time to figure this out and had to use the keyword _root which is not recommended when using actionscript 2. If anyone can improve on this code I would like to know.

var myPoint:Object = new Object();
myPoint.x = main_mc.clip2_mc.square_mc._x;
myPoint.y = main_mc.clip2_mc.square_mc._y;
 
_root.main_mc.clip2_mc.localToGlobal(myPoint);
 
box_mc._x = myPoint.x;
box_mc._y = myPoint.y;