[MX] globalToLocal ?!

Ok I’m still working on my loaded swf which is an infinite menu.

I’ve been informed that globalToLocal is what I need (I want the code in the loaded swf to refer to its own (local) x/y cordinates not the main stage 9global0 cordinates). From what I’ve read it seems like this method should solve my problems… however I can’t really find a good explanation of how to use it anywhere. It isnt very intuitive - at least for me. I’ve search these forums, did a google, and have looked it up in the AS dictionary… to no avail.

here is what I’ve got:

onClipEvent(load) {
	loadMovie("infiniteRES.swf",_root.pages.containerRES);
	//something here involving point = new object() ???
	//point.x = _root._xmouse; ???
	//point.y = _root._ymouse; ???
	_root.pages.containerRES.globalToLocal(??);
}
	

I’m not very clear on this point object it says to use in the as dictionary… also do I want to perform globalToLocal on the container MC or the loaded swf directly? and why in the AS dictionary does it do this:
_root.MCtoGetMethod.globalToLocal(point) - it directs it at point? but is targeted to the MC I want??

For the life of me I cant find a clear explanation of this method… some help on this would be great.

oh and here is the code on the infinite MC inside the loaded swf:

onClipEvent (load)
{
   xcenter=125;
   speed=1/10;
}
onClipEvent (enterFrame)
{
if (_root._xmouse < 33 | _root._xmouse > 218 | _root._ymouse < 18 | _root._ymouse > 62) speed=0;
	else speed=1/10;
   var distance=_root._xmouse-xcenter;
   _x-=(distance*speed);
   if (_x > 0) _x=-893;
   if (_x < -893) _x=0;
   
}

peace

:bump: :blush:

globalToLocal takes a point and converts it to the local coordinates of the mc scope it is being called in.

Imagine a mc “A” at (100, 100). Now if your mouse cursor is at (200, 200) wrt the root stage. What globalToLocal will do is calculate the coordinates of the point wrt the mc “A” instead. In this case you can make out that if the cursor is at (200, 200) it is at (100, 100) wrt the mc “A”.


createEmptyMovieClip ("mc", 1);
mc.beginFill (0x000000);
mc.lineTo (100, 0);
mc.lineTo (100, 100);
mc.lineTo (0, 100);
mc.endFill ();

mc._x = mc._y = 100;

function onMouseUp () {
	var pt = new Object ();
	pt.x = _root._xmouse;
	pt.y = _root._ymouse;
	
	mc.globalToLocal (pt);
	trace ("ptRel (" + pt.x + ", " + pt.y + ")");
};

One important thing to remember is the coordinate translation occurs on the point object passed in itself, globalToLocal and localToGlobal donot return a new point.

Most of the time i use this method when i need to translate coordinates from one mc to another. So i use localToGlobal to first translate the coordinates to the global ones and then use globalToLocal with the scope of the target mc to get coordinates in the scope of the target mc.

ok that explanation helped quite a bit, thanks! However I am still not totally clear how to apply this method in my case… infact now that I read your explanation I am starting to doubt that this is what I need to be doing, I think there might be a better way for my situation. Or maybe not. :-/

Does anyone one have any more input or knowledge they could lend me??

Thanks again arcarox

peace