2011-08-01 5 views
3

マウスがコンポーネントの別の部分に移動したときに、さまざまなことを示すツールチップが必要です。たとえば、コンポーネントの上半分の場合は、1つのツールチップが表示されます。マウスがセグメントの下半分にある場合、ツールチップは別のものになります。私は文字列を含むパネルを返すように書かれたコードをいくつか持っています。このコードは別のコンピュータにありますので、明日はコードを投稿します。アクションスクリプトのコンポーネントのさまざまな部分のツールチップ

セグメントの異なる部分について、ActionScriptで異なるツールチップ(ツールチップ内で異なる値)を使用することは可能ですか?

私がこれまで持っているコードは次のとおりです。

MyToolTip.mxml

<?xml version="1.0"?> 
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" 
implements="mx.core.IToolTip" 
alpha=".9" width="325" borderColor="black" borderStyle="solid" 
cornerRadius="10" horizontalAlign="center"> 
<mx:Script><![CDATA[ 
[Bindable] 
public var toolTipText:String = ""; 

public var _text:String; 
[Bindable] 
public function get text():String { return _text; } 
public function set text(value:String):void {} 
]]></mx:Script> 

<mx:HBox width="100%" height="100%"> 
<mx:Text text = "Text here" width = "50%"/> 
<mx:Text text = "{toolTipText}" width = "50%"/> 
</mx:HBox> 
</mx:Panel> 

そして私は、ツールチップが反対になりたい私のアクションスクリプトクラスコンポーネント。

public class MyComponent extends mx.containers.VBox { 

    private var tt:MyToolTip 

    public function MyComponent() { 
     this.addEventListener(ToolTipEvent.TOOL_TIP_CREATE, toolTipCreateHandler); 
     this.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler); 
     tt = new MyToolTip(); 
    } 

    override protected function drawFigure():void { 
     //Need to kick the TOOL_TIP_CREATE event...and needs to be a value (eg a SPACE). 
     //If blank then no tooltip is created 
     this.toolTip = " "; 
     super.drawFigure(); 
    } 

    private function toolTipCreateHandler(event:ToolTipEvent):void { 
     var toolTipText:String = "tooltip1"; 
     eventToolTip.toolTipText = toolTipText; 
     event.toolTip = tt; 
    } 

    private function mouseOverHandler(event:MouseEvent):void { 
     //perhaps I need to be more efficient here and only fire 
     //when the mouse goes into top half or bottom half 
     //This does not appear to update the toolTipText in the view 
     var halfwayUp:Number = getBounds(this).height/2; 
     if (event.localY < halfwayUp) { 
      eventToolTip.toolTipText = "tooltip2"; 
     } 
     else { 
      eventToolTip.toolTipText = "tooltip1"; 
     }   
    } 
} 
} 

既に表示されているときにツールチップを更新する方法についてのヘルプや説明は素晴らしいものです。

+0

フレックスやフラッシュなどのコンポーネントフレームワークは使用していますか? –

+0

次へ:2つのツールチップの違いは何ですか?ちょうどテキストや色、形やその他のもの? –

+0

ツールチップはフラッシュコンポーネントにあります。私のコードは別のコンピュータ上にあるので、申し訳ありませんが、正確なコンポーネントを覚えていません。コンポーネントの内容は単なるテキストです。私はそれがうまくフォーマットされるように、パネル上にテキストのリストを入れています。基本的にはキーと値のペアの束です。キーと値のペアは、マウスがコンポーネント上をホバーする場所によって異なります。 – RNJ

答えて

2

はい、そのヒントは、ツールチップの仕組みを知ることです。
コンポーネント上にマウスを置くとツールチップが作成され、マウスを外すとツールチップが作成されます。したがって、表示中にツールチップ上のテキストを変更すると、set toolTip()関数が既に新しいツールチップを作成していないため、変更が反映されません。だから解決策は、現在表示されているツールチップを破棄し、新しいツールチップを作成することです。ツールチップを破棄するには、その値を空の文字列に設定します。

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application 
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
mouseMove="application1_mouseMoveHandler(event)"> 
<mx:Script> 
<![CDATA[ 
    import mx.managers.ToolTipManager; 

    protected function application1_mouseMoveHandler(event:MouseEvent):void{ 
     if (mouseX < 100) { 
      testButton.toolTip = "" 
      testButton.toolTip = "on the left side"; 
     } else { 
      testButton.toolTip = "" 
      testButton.toolTip = "on the right side"; 

     } 
    } 

]]> 
</mx:Script> 
<mx:Button id="testButton" label="test" width="200" height="200" /> 
</mx:Application> 

注:
は、ここでのサンプルコードで、あなたがより多くのFlexでツールチップを台無しにしたい場合は、あなたがToolTipManager.currentToolTipと現在のツールチップを取得する(そしてそれを破壊することなく、そのプロパティを変更する)ことができます。

+0

ありがとうございます。私はあなたの助けに感謝します! – RNJ

関連する問題