2013-05-10 70 views
0

我有問題需要將焦點設置爲打開彈出窗口的按鈕。 按鈕獲得焦點,但它沒有得到聚焦的外觀。 就好像沒有組件是焦點。在flex中打開彈出窗口時將焦點設置在按鈕中

我的源代碼:

<?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> 

感謝。

+0

你已經包含了很多代碼;你可能會考慮嘗試更專注一點。我沒有看到你嘗試設置焦點的地方。 – JeffryHouser 2013-05-10 13:42:12

+0

你好。 Trying是中的方法creationComplete =「titlewindow1_creationCompleteHandler(event)」。 – user2370074 2013-05-13 11:31:19

回答

0

我通過一個簡單的,但不知道它爲什麼工作。當我打開彈出窗口時,我着重配置了第一個,然後是TextInput,然後在Button中。

相關問題