参考:https://blog.csdn.net/liruizhuang/article/details/5876455
<?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">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<!-- Flex中如何利用FocusManager类的setFocus函数设置TextInput的焦点的例子 -->
<fx:Script>
<![CDATA[
import mx.controls.Alert; private function submitButton_click(evt:MouseEvent):void {
Alert.show(evt.currentTarget.label,
Object(focusManager.getFocus()).name);
} private function resetButton_click(evt:MouseEvent):void {
username.text = "";
password.text = "";
Alert.show(evt.currentTarget.label,
Object(focusManager.getFocus()).name);
}
]]>
</fx:Script> <mx:ApplicationControlBar dock="true">
<mx:Button label="Set focus to Username"
click="focusManager.setFocus(username);" />
<mx:Button label="Set focus to Password"
click="focusManager.setFocus(password);" />
</mx:ApplicationControlBar> <mx:Form id="form"
defaultButton="{submitButton}" left="300">
<mx:FormItem label="Username:">
<mx:TextInput id="username" />
</mx:FormItem>
<mx:FormItem label="Password:">
<mx:TextInput id="password"
displayAsPassword="true" />
</mx:FormItem>
<mx:FormItem direction="horizontal"
horizontalAlign="right"
width="100%">
<mx:Button id="submitButton"
label="Submit"
click="submitButton_click(event);" />
<mx:Button id="resetButton"
label="Reset"
click="resetButton_click(event);" />
</mx:FormItem>
</mx:Form> </s:Application>