2008-12-19 90 views
3

我们的Flex应用程序会自动调整浏览器窗口的大小,我们已经很容易地解决了一大堆缩放问题,但剩下的就是提示。它们显示在屏幕上的错误位置,没有根据窗口大小正确缩放。由于工具提示自动定位,我们如何解决这个问题?Flex Tooltip在可调整大小的应用程序中定位

为了说明我正在使用内置的flex工具提示。问题不在于当应用在显示时调整大小时,工具提示不会移动。这就是说,如果我调整应用程序的大小,即使其他所有内容都能正确自动更新,工具提示现在也会显示在错误的位置。

+0

您使用的是内置的工具提示或您自己的? – PEZ 2008-12-19 14:47:59

回答

0

我不认为有这个问题的一个很好的解决方案,因为ToolTipManager不知道currentTargetToolTip更改舞台上的位置。该解决方案几乎必须进入Flex框架本身。我将一些似乎可行的东西封存在一起,但它需要修改Flex框架。

  1. 复制mx.managers.ToolTipManager.as到创建mx.managers包项目。

  2. 将此方法添加到文件的底部。

    public static function positionToolTip() : void { 
        ToolTipManagerImpl(impl).positionTip(); 
    } 
    
  3. 在您的应用程序的resize事件中调用此方法。

3

不知道你是否找到了这个解决方案,但有一个更简单的方法。这段代码在捕获阶段(在显示之前)钩住工具提示显示事件,根据包含元素的比例来适当缩放和放置它 - 在“本”情况下,parentApplication文档。它还包括一些代码,在我的情况,有助于保持漂移离开舞台的工具提示缩放时(所以你可能只需要第几行 - t.scaleXt.scaleY):

import mx.events.ToolTipEvent; 

addEventListener(ToolTipEvent.TOOL_TIP_SHOW, handleToolTipShow, true, 0, true); 

private function handleToolTipShow(event:ToolTipEvent):void 
{ 
    if (event && event.toolTip) 
    { 
     var t:IToolTip = event.toolTip; 

     // Scale the tip itself 
     t.scaleX = this.scaleX; 
     t.scaleY = this.scaleY; 

     // Scale the offsets 
     var xOffset:int = 10 * this.scaleX; 
     var yOffset:int = 10 * this.scaleY; 

     // Set the default positioning 
     t.x = parent.mouseX + xOffset; 
     t.y = parent.mouseY + yOffset; 

     // Set the adjusted height and width 
     var th:Number = t.height * this.scaleX; 
     var tw:Number = t.width * this.scaleY; 

     var rightEdge:int = t.x + tw + xOffset; 
     var playerRightEdge:int = parent.width; 
     var bottomEdge:int = t.y + th + yOffset; 
     var playerBottomEdge:int = parent.height; 

     // Offscreen right 
     if (rightEdge > playerRightEdge) 
     { 
      t.move(parent.mouseX - xOffset - tw, parent.mouseY + yOffset); 
     } 

     // Offscreen bottom 
     if (bottomEdge > playerBottomEdge) 
     { 
      t.move(parent.mouseX + xOffset, parent.mouseY - yOffset - th); 
     } 
    } 
} 
0

尝试转换使用contentToGlobal坐标到全球()

相关问题