1 Reply Latest reply on Nov 6, 2009 7:34 AM by J_Carter

    Position a ToolTip in a Child Window

    Typidee Level 1

      Hello,

           I am trying to figure out how to position a tooltip in a window that is a child of the main WindowedApplication.  I have a common control composed of a canvas containing a single mx:Image.  The control contains code for displaying a tooltip over the image on mouse over.  When this control is instantiated as a descendant of the main application window, the positioning works as expected.

       

           However, when this control is placed in a child mx:Window spawned from the main window, the positioning and z-order of the tooltip are incorrect.  In this case, the tooltip is displayed inside the main window in the upper left.  Here's the code for the control in question:

       

      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()" mouseOver="showToolTip(event)" mouseOut="killToolTip()" paddingTop="0">
      <mx:Script>
          <![CDATA[
              private function showToolTip(evt:MouseEvent):void
              {

                  var pt:Point = new Point(evt.currentTarget.x, evt.currentTarget.y);
                 
                  // Convert the targets 'local' coordinates to 'global' -- this fixes the
                  // tooltips positioning within containers.
                  pt = evt.currentTarget.parent.contentToGlobal(pt);

       

                 // Create a simple tooltip that appears at the mouse x and y position
                 var tip:String = rosterItem.displayName + "\n" + rosterItem.status;
                 m_toolTip = ToolTipManager.createToolTip(tip, pt.x, pt.y, "errorTipAbove") as ToolTip;
                 m_toolTip.styleName = "statusToolTip";
                
                 var yOffset:int =  m_toolTip.height + 3;
                  m_toolTip.y -= yOffset;
                  m_toolTip.x += 5;

              }

          ]]>


      </mx:Script>
          <mx:Image id="imgAvatar" source="{m_imageData}" scaleContent="true" left="2" right="0" top="0" bottom="2"/>
         
      </mx:Canvas>

       

      Any help would be sincerely appreciated.

        • 1. Re: Position a ToolTip in a Child Window
          J_Carter

          The problem is that the ToolTipManager does not have an appropriate context.  The fix is quite simple:

           

          ToolTipManager.createToolTip("Try pressing the keys even harder", xCoord, yCoord, "errorTipRight", this);

           

          The addition of 'this' or similar directs the ToolTipManager to the appropriate child window.