2010-07-27 36 views
5

我試圖讓一個帶有可立即編輯的TextInput的彈出窗口。這意味着一旦顯示彈出窗口,用戶應該能夠在TextInput內輸入內容。將焦點設置在Popup的textInput控件上

問題是我無法專注於textInput。會發生什麼情況是,當第一次按下某個鍵時,不會插入文本,只有在按下第二個鍵之後,該組件纔會獲得焦點並且用戶才能夠輸入。例如,一旦彈出窗口打開導致顯示「est」,就會輸入「test」...

由於某些原因,組件僅在用戶明確點擊或鍵入內容時獲得焦點。 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> 
+0

你有彈出 – Grumpy 2010-07-27 11:04:48

回答

2

的問題是,我是觸發與F10鍵彈出呼叫。 F10是系統保留的...它確實觸發了處理程序,彈出窗口已創建,但不知何故應用程序失去了焦點。使用另一個鍵修復它。唯一的保留鍵是F10。 More about that

0

這取決於你如何努力做到這一點。什麼工作對我來說是處理彈出的creationComplete事件:

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

PS:在「處理程序」的例子是通過MXML添加所以它沒有參數。

+0

出您使用的是什麼操作系統和瀏覽器的好奇心按預期方式不工作... – 2010-07-27 11:31:13

+0

的來源是什麼? – 2010-07-27 14:01:21

0

以下是對我有用的東西。在creationComplete事件彈出窗口:

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

這確實有效......問題完全是另一回事。我正在使用F10鍵來觸發彈出窗口。恰巧F10是系統保留的。使用另一個鍵很好。 – 2010-09-01 15:47:14

0
在我的情況

我只是實現了IFocusManagerContainer在我的自定義組件,一切運行良好

私人VAR _defaultButton:IFlexDisplayObject中=/默認組件 /;

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