Flex中如何利用FocusManager类的setFocus函数,设置TextInput的焦点

main.mxml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Applicationname="FocusManager_setFocus_test"
  3. xmlns:mx="http://www.adobe.com/2006/mxml"
  4. layout="vertical"
  5. verticalAlign="middle"
  6. backgroundColor="white">
  7. <mx:Script>
  8. <![CDATA[
  9. import mx.controls.Alert;
  10. private function submitButton_click(evt:MouseEvent):void {
  11. Alert.show(evt.currentTarget.label,
  12. Object(focusManager.getFocus()).name);
  13. }
  14. private function resetButton_click(evt:MouseEvent):void {
  15. username.text = "";
  16. password.text = "";
  17. Alert.show(evt.currentTarget.label,
  18. Object(focusManager.getFocus()).name);
  19. }
  20. ]]>
  21. </mx:Script>
  22. <mx:ApplicationControlBardock="true">
  23. <mx:Buttonlabel="Set focus to Username"
  24. click="focusManager.setFocus(username);"/>
  25. <mx:Buttonlabel="Set focus to Password"
  26. click="focusManager.setFocus(password);"/>
  27. </mx:ApplicationControlBar>
  28. <mx:Formid="form"
  29. defaultButton="{submitButton}">
  30. <mx:FormItemlabel="Username:">
  31. <mx:TextInputid="username" />
  32. </mx:FormItem>
  33. <mx:FormItemlabel="Password:">
  34. <mx:TextInputid="password"
  35. displayAsPassword="true"/>
  36. </mx:FormItem>
  37. <mx:FormItemdirection="horizontal"
  38. horizontalAlign="right"
  39. width="100%">
  40. <mx:Buttonid="submitButton"
  41. label="Submit"
  42. click="submitButton_click(event);"/>
  43. <mx:Buttonid="resetButton"
  44. label="Reset"
  45. click="resetButton_click(event);"/>
  46. </mx:FormItem>
  47. </mx:Form>
  48. </mx:Application>

你可能感兴趣的:(xml,Flex,Adobe)