I am attempting to create a JS, that when used will discover the absolute position of an named object, regardless of whether its in a batcher, a few bpatchers, or in the parent itself.
A workaround ive found is to use this.patcher.parentpatcher,which seems to resolve parent bpatchers properly. However, it stops once it reaches the patch that contains the bpatcher, (ie, only one level above), and will not iterate to any other parent patchers.
The following code works properly when called from either the main patch, or the parent patch, but no futher above the patcher heirarchy.
I am obviously misunderstanding something. Id love a pointer in the right direction.
obj = this.patcher.getnamed(name);
objCoords= obj.rect; // get the cordinates from within the objects patch
windowCoords = this.patcher.wind.location; //get the window coords
prev = 0;
owner = this.patcher.parentpatcher;
prev = owner;
owner = owner.patcher.parentpatcher; //iterate up.
post("top patcher is", prev.name); //debug
windowCoords = prev.wind.location; // set the window coords to the topmost window
// get our x/y position from window and local coords
x = windowCoords + objCoords;
y = windowCoords + objCoords;
outlet(0, x,y+13, x+126, y+73);
// post(x, y);