2010-10-19 125 views
2

我试图阻止自定义工具提示消失。我已经尝试过三次,从通常的嫌疑犯那里借来:Peter Dehann,MonkeyPatch和其他人。正如你从下面的代码中可以看到的,我希望保持在工具提示范例中,而不是去弹出窗口。Flex - 防止隐藏工具提示。持久工具提示

任何人都可以提出一种方法来坚持工具提示吗?这里的目的是要有一个可以从中剪切和粘贴的组件。

感谢, 道格

<?xml version="1.0" encoding="utf-8"?> 
<s:Application minHeight="600" creationComplete="application1_creationCompleteHandler(event)" 
minWidth="955" 
xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:mx="library://ns.adobe.com/flex/mx" 
xmlns:s="library://ns.adobe.com/flex/spark"> 
<fx:Script> 
    <![CDATA[ 
    import mx.events.FlexEvent; 
    import mx.events.ToolTipEvent; 

    protected function button1_clickHandler(event:MouseEvent):void { 
    // TODO Auto-generated method stub 
    } 

    protected function button1_toolTipCreateHandler(event:ToolTipEvent):void { 
    createCustomToolTip("title", "", event); 
    } 

    // TODO Auto-generated method stub 
    private function createCustomToolTip(title:String, body:String, event:ToolTipEvent):void { 
    var ptt:CustomToolTip = new CustomToolTip(); 
    ptt.title = title; 
    ptt.bodyText = (event.currentTarget as Button).toolTip; 
    event.toolTip = ptt; 
    } 

    protected function button1_toolTipHideHandler(event:ToolTipEvent):void 
    { 
    // TODO Auto-generated method stub 
    event.stopPropagation(); 
    event.preventDefault(); 
    event.stopImmediatePropagation(); 
    } 

    import mx.managers.ToolTipManager; 

    private var tt:CustomToolTip; 
    private var cc:CustomToolTip; 

    private function create_toolTip():void { 
    var str:String = "Tooltip text goes here..."; 
    // We only want one tooltip. 
    if (tt == null) { 
    tt = ToolTipManager.createToolTip(str, 100, 50) as CustomToolTip; 
    } 
    } 

    protected function application1_creationCompleteHandler(event:FlexEvent):void 
    { 
    // TODO Auto-generated method stub 
    mx.managers.ToolTipManager.toolTipClass = CustomToolTip; 
    //mx.managers.ToolTipManager.scrubDelay = 100000; 
    //mx.managers.ToolTipManager.hideDelay = 1000000; 
    } 


    protected function button1_toolTipEndHandler(event:ToolTipEvent):void 
    { 
    event.preventDefault(); 
    event.stopImmediatePropagation(); 
    // TODO Auto-generated method stub 
    } 

    ]]> 
</fx:Script> 
<fx:Declarations> 
    <!-- Place non-visual elements (e.g., services, value objects) here --> 
</fx:Declarations> 
<mx:VBox> 

<mx:Button click="button1_clickHandler(event)" 
    toolTip="helloWorld" toolTipHide="button1_toolTipHideHandler(event)" toolTipEnd="button1_toolTipEndHandler(event)" 
    toolTipCreate="button1_toolTipCreateHandler(event)" > 
</mx:Button> 

<mx:Button label="create tool tip" click="create_toolTip();" /> 

<mx:Button toolTip="hello world" label="hello"> 

</mx:Button> 
</mx:VBox> 
</s:Application> 
+0

您是否尝试过猴子修补ToolTipManager.destoryToolTip方法,以防止其毁灭? – 2010-10-21 10:58:31

回答

0

使用一些JavaScript代码,以显示工具提示中的链接的onmouseover部分:

<a href="page.aspx" onmouseover=showtooltip("Tooltip Text")></a> 

不包括在你的链接任何JavaScript程序一样onmouseout=hidetooltip()它将保持开放。

P.S:你可以把一个链接,在“工具提示文本”,包括onmouseout=hidetooltip(),是这样的:

<a href=originalpage.aspx onclick=hidetooltip()>Close</a> 
+0

有很多showtooltip和hidetooltip类型的JavaScripts的来源,只是谷歌他们。 – Jim 2011-07-21 20:16:00