ポップアップで何がしかの入力画面を開いて、そこの一番上のコンポーネント(例えばテキストフィールド)などにフォーカスを当てたい、場合のやり方。
<?xml version="1.0" encoding="utf-8"?> <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="400" height="300" creationComplete="creationCompleteHandler(event)"> <mx:Script> <![CDATA[ private function creationCompleteHandler(event:Event):void { this.focusManager.setFocus(textInput); } ]]> </mx:Script> <mx:TextInput id="textInput" /> <mx:TextInput id="textInput2" /> </mx:TitleWindow>
UIComponent が持ってる focusManager を使うことでフォーカスの制御が出来る。
また、このケースみたいにウィンドウっていうかコンポーネントの初期化時にフォーカス制御したい場合、creationComplete イベントでやる必要がある。initialize の段階だと focusManager がまだ null なので。
参考:Creating Custom UIComponents in Flex 2: Lesson 1 - Overview UIComponents の初期化手順について書かれている。