Hi Folks:


I've got this code working but I was hoping to get some flexcoders
feedback before I convert it into a Flex Cookbook post.



I've been trying to use the ToolTip Manager to create custom
ToolTips, and I've been using these instructions:

http://livedocs.adobe.com/flex/3/html/help.html?content=tooltips_4.html
<http://livedocs.adobe.com/flex/3/html/help.html?content=tooltips_4.html\
>



But when you get to the section "Positioning custom ToolTips"
the wheels fall off the wagon. To determine where to place your ToolTip
you need to know the location of your control – but the (x, y)
coordinates you get from event.currentTarget vary depending upon whether
your control is located in a container. The function contentToGlobal()
is suppose to help you adjust this position, but this technique seems to
stop working if your control is nested deep within several containers
– and hence it doesn't seem to be a general purpose solution.



In frustration I wrote this code below to find the global screen
location of a control from a mouseOver or FocusIn event. It seems to
work fine - even when you scrunch up the containers and the browser with
horizontal and vertical scrollbars.



Please take a look and let me know if I can tighten up this code, or if
there is a better solution altogether.



Thanks in advance!



private function setLocation(event:Event):void {



     var point:Point = new Point(event.currentTarget.x,
event.currentTarget.y);

     var ancestor:DisplayObject = event.currentTarget.parent;

     var mousePointContent:Point;

     var mousePointContentToLocal:Point;



     // Manually convert the location of the point from the local
coordinate system to the global coordinate system by iterating up the
display list and adjusting for each container

     while (ancestor != ancestor.stage) {

         point.x += ancestor.x;

         point.y += ancestor.y;

         if (ancestor.parent != ancestor.stage) {

             mousePointContent = new
Point(UIComponent(ancestor).contentMouseX,
UIComponent(ancestor).contentMouseY);

             mousePointContentToLocal =
UIComponent(ancestor).contentToLocal(mousePointContent);

             point.x = point.x + mousePointContentToLocal.x -
mousePointContent.x;

             point.y = point.y + mousePointContentToLocal.y -
mousePointContent.y;

         }

         ancestor = ancestor.parent;

     }




     location.x = point.x;

     location.y = point.y;

}




Reply via email to