我有一個火花borderContainer,它包含一個Spark TextInput。 我在borderContainer上有一個mouse_down和mouse_up事件處理程序,以便在屏幕上拖動它;拖動時我改變光標。Flex光標管理問題
我想讓textInput像「標準」textInput一樣工作,即當點擊textInput時,用戶不應該拖動整個組件,而只是簡單地與文本進行交互。另外,我希望textInput遊標看起來像一個普通的textInput遊標。
我不知道我是這樣做的權利。我的假設是,我需要停止textInput上mouse_down和mouse_up的傳播,以禁止其父級的拖動行爲,並管理rollOver和rollOut以使光標看起來正常。看下面我的代碼示例(爲了簡化它,沒有borderContainer或拖動 - 但代碼很簡單 - 只是更長一點)。
所以,這裏的問題是:如果點擊火花textInput,然後滾出它,光標變成一個textInput光標+爲borderContainer設置的標準光標的組合。這似乎沒有發生在mx textInput組件(因此兩個框)上,但不幸的是我需要使用spark組件。我的猜測是,我要麼沒有正確調用cursorManager,要麼我沒有正確地停止mouse_up的傳播 - 它看起來應該擊中textInput,但不會傳播到borderContainer。我也試過stopPropagation(),但沒有運氣。
會愛任何建議/建設性的批評。
謝謝!
˚F
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
creationComplete="application1_creationCompleteHandler(event)"
mouseDown="application1_mouseDownHandler(event)"
mouseUp="application1_mouseUpHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.managers.CursorManager;
[Bindable] [Embed(source="../resources/hand.png")] private var _handIcon:Class;
[Bindable] [Embed(source="../resources/Fist.png")] private var _fistIcon:Class;
private var _cursorID:int;
protected function textinput1_rollOutHandler(e:MouseEvent):void
{
e.stopImmediatePropagation();
CursorManager.removeCursor(_cursorID);
_cursorID = CursorManager.setCursor(_handIcon);
}
protected function textinput1_rollOverHandler(e:MouseEvent):void
{
e.stopImmediatePropagation();
CursorManager.removeCursor(_cursorID);
}
protected function application1_creationCompleteHandler(e:FlexEvent):void
{
_cursorID = CursorManager.setCursor(_handIcon);
}
private function stopPropagation(event:MouseEvent):void
{
event.preventDefault();
event.stopImmediatePropagation();
}
protected function textinput1_mouseDownHandler(event:MouseEvent):void
{
stopPropagation(event);
}
protected function textinput1_mouseUpHandler(event:MouseEvent):void
{
stopPropagation(event);
}
protected function application1_mouseDownHandler(event:MouseEvent):void
{
CursorManager.removeCursor(_cursorID);
_cursorID = CursorManager.setCursor(_fistIcon);
}
protected function application1_mouseUpHandler(event:MouseEvent):void
{
CursorManager.removeCursor(_cursorID);
_cursorID = CursorManager.setCursor(_handIcon);
}
]]>
</fx:Script>
<s:TextInput x="43" y="30"
rollOut="textinput1_rollOutHandler(event)"
rollOver="textinput1_rollOverHandler(event)"
mouseDown="textinput1_mouseDownHandler(event)"
mouseUp="textinput1_mouseUpHandler(event)"/>
<mx:TextInput x="43" y="70"
rollOut="textinput1_rollOutHandler(event)"
rollOver="textinput1_rollOverHandler(event)"
mouseDown="textinput1_mouseDownHandler(event)"
mouseUp="textinput1_mouseUpHandler(event)"/>
呵呵,這麼簡單但很有效。謝謝Maxim! – 2010-10-02 21:54:43
ps - 我使用了一個稍微修改過的版本,但使用容器和運行檢查的想法起作用。 – 2010-10-02 22:23:13