我想要一個工具提示,當鼠標移過組件的不同部分時,它會顯示不同的東西。例如,如果它是組件的上半部分,它將顯示一個工具提示。如果鼠標位於該段的下半部分,則工具提示將是另一個。我有一些我寫的代碼返回一個字符串中的面板。這段代碼是在另一臺計算機上,所以我明天會發布代碼。動作腳本中組件不同部分的不同工具提示
是否有可能在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";
}
}
}
}
任何幫助或指示如何更新工具提示,當它已經顯示會很好。
您是否使用任何組件框架(如flex或flash)? –
下一頁:兩個工具提示有什麼不同?只是文字或顏色,形狀和其他東西? –
工具提示位於閃存組件上。對不起,我不記得確切的組件,因爲我的代碼在另一臺計算機上。組件中的東西只是文本。我在面板上放置了一個文本列表,以便格式化得很好。這本質上是一堆鍵值對。鍵值對將根據鼠標懸停在組件上的位置而有所不同。 – RNJ