【问题标题】:set focus in button when open popup in flex在flex中打开弹出窗口时在按钮中设置焦点
【发布时间】:2013-05-10 13:37:45
【问题描述】:

我无法将焦点设置在按钮上以打开弹出窗口。 按钮获得焦点,但没有获得焦点的外观。 好像没有任何组件是焦点。

我的源代码:

<?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:Script>
    <![CDATA[
        import comps.MyPopUpWindow;

        import mx.events.FlexEvent;
        import mx.managers.PopUpManager;

        // declare a variable for the reusable custom PopUp Window
        private var popup:MyPopUpWindow;

        private function openPopUpWindow(evt:FlexEvent=null):void {
            // open the PopUp Window as a modal popup window
            // and store it in a variable for later use
            popup = PopUpManager.createPopUp(this,MyPopUpWindow,true)  as MyPopUpWindow;
        }

        protected function button1_clickHandler(event:MouseEvent):void
        {
            openPopUpWindow();
        }

    ]]>
</fx:Script>

<s:Button click="button1_clickHandler(event)" label="Open popup"/>  
</s:Application>

弹出窗口:

<mx:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" 
            xmlns:s="library://ns.adobe.com/flex/spark" 
            xmlns:mx="library://ns.adobe.com/flex/mx" 
            width="400" height="300"
            layout="vertical"
            title="Title"
            showCloseButton="true"                                                          
            keyDown="titlewindow1_keyDownHandler(event)"
            close="titlewindow1_closeHandler(event)"
  creationComplete="titlewindow1_creationCompleteHandler(event)">       

<fx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.core.IFlexDisplayObject;
        import mx.events.CloseEvent;
        import mx.events.FlexEvent;
        import mx.managers.IFocusManagerComponent;
        import mx.managers.PopUpManager;

protected function titlewindow1_creationCompleteHandler(event:FlexEvent):void
        {
            login.setFocus();                           
            var componente:Button = focusManager.getFocus() as Button;
//Alert.show(componente.name ,'Save'); to ensure that the component holds the focu.                     
        }           

protected function titlewindow1_keyDownHandler(event:KeyboardEvent):void
        {
if (event.charCode == Keyboard.ESCAPE) {
        this.dispatchEvent(new CloseEvent(CloseEvent.CLOSE));
            }
        }

        protected function titlewindow1_closeHandler(event:CloseEvent):void
        {
        PopUpManager.removePopUp(event.target as IFlexDisplayObject);
        }


        protected function save_keyDownHandler(event:KeyboardEvent):void
        {
            if (event.keyCode == Keyboard.ENTER) 
                Alert.show('Login','Login');            
        }

        protected function login_clickHandler(event:MouseEvent):void
        {
            Alert.show('Login','Login');            
        }       
    ]]>
</fx:Script>    


<mx:Button id="login" label="Login"     click="login_clickHandler(event)"/>

<mx:Button id="cancel" label="Cancel" />            

</mx:TitleWindow>

谢谢。

【问题讨论】:

  • 你已经包含了很多代码;您可以考虑尝试更加专注。我没有看到您尝试设置焦点的地方。
  • 你好。尝试的是 中的方法 creationComplete="titlewindow1_creationCompleteHandler(event)" 。

标签: actionscript-3 apache-flex flex4 flex3 flex4.5


【解决方案1】:

【讨论】:

    【解决方案2】:

    我通过了一个简单的,但不知道为什么它会起作用。当我打开弹出窗口时,我首先配置了 TextInput,然后是 Button。

    【讨论】:

      猜你喜欢
      • 2012-07-08
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-18
      • 1970-01-01
      相关资源
      最近更新 更多