How to get absolute X/Y coordinates of an item

It’s easy to parse the style tag of an item and read its top and left
properties if it’s a layer. But this method falls down if the item in
question is grouped or otherwise nested within another object, or if
it is not a layer.

Is there any way to get the geometry of a fwItem with respect to the
page itself, ignoring any parents?

Thanks,

Walter


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Answering my own question…

Here’s a partial solution. I haven’t tested to see what it does on a non-layer item, it might work.

This is a recursive function that creates a pair of dummy variables on the item, and then walks up the tree to find the cumulative offset from 0,0. The return value is an array of (top,left) as integers.

function getPosition(item){
	if(!item['_top']) item['_top'] = item.fwTop;
	if(!item['_left']) item['_left'] = item.fwLeft;
	if(item.fwParent){
		var p = item.fwParent;
		if(p.toString().indexOf("PageDiv") < 0){
			p['_top'] = item._top + p.fwTop;
			p['_left'] = item._left + p.fwLeft;
			return getPosition(p);
		}
	}
	return [item._top,item._left];
}

This feels sort of hacky to me, it would be nice if Freeway would just tell us this directly without so much introspection. I stand ready to be told that there’s an undocumented property like fwItem.fwAbsTop hiding in there somewhere…

Walter


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Since the inspector doesn’t even show you the absolute location of the item, I wonder if it’s even “recorded” anywhere in Freeway. To my mind, the absolute coordinates should be in the “Screen Measurements” area, and the relative positioning under “Dimensions” if it’s a child item.

Here’s something related that’s strange. I drew an HTML item on the page, then drew a child HTML item inside it. While I was drawing the child item, the X and Y coords were the absolute value on the page. As soon as I was finished drawing, both sets of X/Y coords popped to show the relative location.


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi,

The top/left was introduced in Freeway 3 (as I remember) and when we moved to nested items it returns the relative co-ordinates.

Alan


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

So could the “real” top/left please stand up in Freeway 5? As Joe
pointed out, it is known to Freeway up until the moment the mouse
cursor is released on a draw. Does anyone else need this, or am I
alone in wanting to “absolutize” elements at whim inside an Action?

Walter

On Jun 30, 2008, at 10:37 AM, alan wrote:

Hi,

The top/left was introduced in Freeway 3 (as I remember) and when
we moved to nested items it returns the relative co-ordinates.

Alan


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options