簡體   English   中英

將焦點設置在Popup的textInput控件上

[英]Setting focus on a Popup's textInput control

我正在嘗試使用可立即編輯的TextInput的彈出窗口。 這意味着一旦顯示彈出窗口,用戶應該能夠在TextInput中鍵入內容。

問題是我無法專注於textInput。 發生的情況是,當第一次按下某個鍵時,不會插入任何文本,只有在按下第二個鍵后,該組件才會獲得焦點並且用戶可以鍵入。 例如,打開彈出窗口后鍵入“test”會導致顯示“est”...

由於某種原因,組件僅在用戶明確單擊或鍵入內容時獲得焦點。 Programmaticaly設置焦點不起作用。

有什么想法/建議嗎?

碼:

<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns="mog.miss.component.*" xmlns:mx="http://www.adobe.com/2006/mxml" >

<mx:Script>
    <![CDATA[
        import mx.managers.IFocusManagerComponent;

        private function focus():void{
            focusManager.setFocus(commentTextInput as IFocusManagerComponent);
            commentTextInput.setSelection(commentTextInput.text.length,commentTextInput.text.length);
        }

    ]]>
</mx:Script>
<mx:TextInput id="commentTextInput" creationComplete="{focus()}" />

</mx:Panel>

問題是我用F10鍵觸發了彈出調用。 F10是系統保留的......它確實觸發了處理程序並且創建了彈出窗口,但不知何故應用程序失去了焦點。 使用另一個鍵修復它。 唯一保留的密鑰是F10。 更多關於這一點

在我的情況下,我剛剛在我的自定義組件中實現了IFocusManagerContainer,一切正常

private var _defaultButton:IFlexDisplayObject = / default component /;

    public function get defaultButton():IFlexDisplayObject{
        return _defaultButton;
    }
    public function set defaultButton(value:IFlexDisplayObject):void{
        _defaultButton = value;
        ContainerGlobals.focusedContainer = null;
    }

這取決於你如何嘗試這樣做。 對我有用的是處理彈出窗口的creationComplete事件:

private function onCreationComplete():void 
{
    focusManager.setFocus(this.mytextInput as IFocusManagerComponent);
}

PS:示例中的“處理程序”是通過mxml添加的,因此它沒有參數。

這對我有用。 在彈出窗口的creationComplete事件中:

private function onCreationComplete():void
{
  callLater(this.commentTextInput.setFocus);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM