OK, so I answered this one myself =)

DisplayObject has a function called localToGlobal() that takes a local
point, and returns one relative to the stage (global). It also has a
'partner' function called globalToLocal() which does the opposite.

So to get a point relative to an ancestor container, you call:

ancestor.globalToLocal(child.localToGlobal(child.x,child.y));

cheers!
Thunder

--- In flexcoders@yahoogroups.com, "thunderstumpgesatwork"
<[EMAIL PROTECTED]> wrote:
>
> Hi all,
> 
> I am trying to catch a selection change event on a chart, and then
> position and show an HBox relative to a corner of the chart item.
> 
> The HBox is a child of an outer canvas which houses several other
> containers including the chart, legend, etc. 
> 
> The X and Y position of the HBox is relative to the outer Canvas, but
> the X and Y position I have is for the chart item, and it's renderer.
> 
> Are there any built-in functions that will convert the X-Y position on
> the chart item to it's ancestor (the canvas)? 
> 
> If not, would this recursive search up the 'parent' chain be an
> appropriate approach to doing so? It works for my situation, but I
> don't know if all 'parent' objects are required to have both an x-y
> combination and a 'parent' object as well...
> 
> thanks,
> Thunder
> _______________________
> 
> public function translateCoordinates(referenceObject:Object,
> ancestor:Object):Object
> {
>    var oRet:Object=null;
>    if ( (referenceObject != null) &&
>         (referenceObject.x != null) &&
>         (referenceObject.y != null) &&
>         (referenceObject.parent != null) &&
>         (ancestor != null)
>        )
>    {
>       // assume we have valid objects
>       if (referenceObject.parent == ancestor)
>       {
>          // the object's parent is the ancestor. its coordinates are
> relative to the ancestor
>          oRet = new Object();
>          oRet.x = referenceObject.x;
>          oRet.y = referenceObject.y;
>       }
>       else
>       {
>          // keep looking up the chain of parents
>          var oPos:Object =
> translateCoordinates(referenceObject.parent, ancestor);
>          if (oPos != null)
>          {
>             // the relative position was found, add it to the current
> reference object
>             oRet = oPos;
>             oRet.x = referenceObject.x + oPos.x;
>             oRet.y = referenceObject.y + oPos.y;
>          }
>       }
>    }
>    return oRet;
> }
>







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to