学IT就来ACCP教程网
您的位置:ACCP教程网图文教程flex教程 ┳ 内容

Flex3表单中回车下移焦点实例

时间:2010-01-03 11:10:23 |来源:网络 |作者:秩名 |点击:

对于习惯了使用桌面应用程序的用户而言,回车后下移焦点到下一个编辑组件中的小功能,是非常贴心的,利用flex中的KEY_DOWN事件可以方便的实现回车下移焦点,代码如下:

 
<?xml version="1.0" encoding="utf-8"?>  
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"  creationComplete="CreationComplete()"  height="398" width="518" backgroundColor="#E6E3E3">  
<mx:Script>  
    <!--[CDATA[  
        import mx.containers.HBox;  
        import mx.core.UIComponent;  
        import mx.events.CloseEvent;  
        import mx.controls.Alert;  
          
        public function CreationComplete():void{  
            var monthNames:Array=new Array;  
            var dayNames:Array=new Array;  
              
            monthNames.push("一","二","三","四","五","六","七","八","九","十","十一","十二");  
            dayNames.push("日","一","二","三","四","五","六");  
            this.edtccrq.monthNames = monthNames;//中文月份名  
            this.edtgrrq.monthNames = monthNames;  
            this.edtrzrq.monthNames = monthNames;  
            this.edtccrq.dayNames = dayNames;//中文星期名  
            this.edtgrrq.dayNames = dayNames;  
            this.edtrzrq.dayNames = dayNames;  
            this.edtccrq.formatString = "YYYY-MM-DD";//本地日期格式  
            this.edtgrrq.formatString = "YYYY-MM-DD";;  
            this.edtrzrq.formatString = "YYYY-MM-DD";  
              
              
            //以下批量添加事件监视  
            var childs:Array= this.mainvbox.getChildren();  
            //取出顶级对象的子组件集合  
            var item:Object;  
            for each (item in childs){  
                if (item is HBox){  
                     var items:Array = (item as HBox).getChildren();  
                     //取出HBox中的子组合集合  
                     var subitem:Object;  
                      for each (subitem in items){  
                         if (subitem is UIComponent) {  
                            (subitem as UIComponent).addEventListener(KeyboardEvent.KEY_DOWN,this.onKeyDown);  
                            //给组件注册KEY_DOWN事件。  
                         }  
                      }  
                }  
           }  
        }  
      
 
    private function btncloseclick():void{  
       this.parentApplication.panelassetedit.visible=false;  
       this.parentApplication.panellist.visible=true;  
    }         
      
    private function onKeyDown(e:KeyboardEvent):void{  
    if (e.keyCode==Keyboard.ENTER){  
          
        var tab:int=(e.currentTarget as UIComponent ).tabIndex;  
        var childs:Array= this.mainvbox.getChildren();  
        var item:Object;  
        for each (item in childs){  
              if (item is HBox){  
                 var items:Array = (item as HBox).getChildren();  
                 var subitem:Object;  
                 for each (subitem in items){  
                  if ((subitem as UIComponent).tabIndex != -1) {  
                       if ((subitem as UIComponent).tabIndex==tab+1){  
                            (subitem as UIComponent).setFocus();  
                       }                    
                  }  
 
                 }  
              }   
         }  
     }    
          
    }  
      
    ]]-->  
</mx:Script>  
    <mx:VBox id="mainvbox" x="0" y="0" height="388" width="518" fontSize="12">  
            <mx:HBox width="100%" height="28" paddingTop="3">  
            <mx:Label text="资产编号" height="20" width="62" textAlign="right"/>  
            <mx:TextInput height="20" id="edtzcbh" tabIndex="0"/>  
            <mx:Label text="资产名称" height="20" width="62" textAlign="right"/>  
            <mx:TextInput height="20" id="edtzcmc" tabIndex="1"/>  
        </mx:HBox>  
          
        <mx:HBox width="100%" height="28" paddingTop="3">  
            <mx:Label text="规格型号" height="20" width="62" textAlign="right"/>  
            <mx:TextInput height="20" tabIndex="2" id="edtggxh"/>  
            <mx:Label text="资产类别" height="20" width="62" textAlign="right"/>  
            <mx:ComboBox height="20" tabIndex="3" id="edtzclb"></mx:ComboBox>  
        </mx:HBox>  
          
        <mx:HBox width="100%" height="28" paddingTop="3">  
            <mx:Label text="生产厂家" height="20" width="62" textAlign="right"/>  
            <mx:TextInput height="20" width="397" tabIndex="4" id="edtsccj"/>  
        </mx:HBox>  
          
        <mx:HBox width="100%" height="28" paddingTop="3">  
            <mx:Label text="出厂日期" height="20" width="62" textAlign="right"/>  
            <mx:DateField width="159" height="20" id="edtccrq" tabIndex="5"/>  
            <mx:Label text="资产来源" height="20" width="62" textAlign="right"/>  
            <mx:ComboBox height="20" tabIndex="6" id="edtzcly"></mx:ComboBox>  
        </mx:HBox>  
          
        <mx:HBox width="100%" height="28" paddingTop="3">  
            <mx:Label text="使用部门" height="20" width="62" textAlign="right"/>  
            <mx:ComboBox height="20" tabIndex="7" id="edtsybm"></mx:ComboBox>  
            <mx:Label text="使用情况" height="20" width="62" textAlign="right"/>  
            <mx:ComboBox height="20" tabIndex="8" id="edtsyqk"></mx:ComboBox>  
        </mx:HBox>  
          
        <mx:HBox width="100%" height="28" paddingTop="3">  
            <mx:Label text="存放地点" height="20" width="62" textAlign="right"/>  
            <mx:TextInput height="20" tabIndex="9" id="edtcfdd"/>  
            <mx:Label text="使用人员" height="20" width="62" textAlign="right"/>  
            <mx:ComboBox height="20" tabIndex="10" id="edtsyyy"></mx:ComboBox>  
        </mx:HBox>  
        <mx:HBox width="100%" height="28" paddingTop="3" tabIndex="12">  
            <mx:Label text="购入日期" height="20" width="62" textAlign="right"/>  
            <mx:DateField width="159" height="20" id="edtgrrq" tabIndex="11"/>  
            <mx:Label text="入帐日期" height="20" width="62" textAlign="right"/>  
            <mx:DateField width="159" height="20" id="edtrzrq" tabIndex="12"/>  
        </mx:HBox>  
        <mx:HBox width="100%" height="28" paddingTop="3">  
            <mx:Label text="预计使用年限" height="20" width="90" textAlign="right"/>  
            <mx:TextInput height="20" width="131" tabIndex="13" id="edtsynx"/>  
            <mx:Label text="净残值率" height="20" width="62" textAlign="right"/>  
            <mx:TextInput height="20" tabIndex="14" id="edtjczl"/>  
        </mx:HBox>  
        <mx:HBox width="100%" height="28" paddingTop="3">  
            <mx:Label text="计量单位" height="20" width="62" textAlign="right"/>  
            <mx:ComboBox width="63" height="20" tabIndex="15" id="edtjldw"></mx:ComboBox>  
            <mx:Label text="数量" height="20" width="34" textAlign="right"/>  
            <mx:TextInput height="20" width="54" tabIndex="16" id="edtsl"/>  
            <mx:Label text="单价" height="20" width="32" textAlign="right"/>  
            <mx:TextInput height="20" width="57" tabIndex="17" id="edtdj"/>  
            <mx:Label text="金额" height="20" width="32" textAlign="right"/>  
            <mx:TextInput height="20" width="75" tabIndex="18" id="edtje"/>  
        </mx:HBox>  
        <mx:HBox width="100%" height="28" paddingTop="3">  
            <mx:Label text="备注" height="20" width="62" textAlign="right"/>  
            <mx:TextInput height="20" width="397" tabIndex="19" id="edtbz"/>  
        </mx:HBox>  
        <mx:ApplicationControlBar width="100%" height="37" fontSize="12" fillAlphas="[0.89, 1.0]" fillColors="[#CCCCCC, #E6E3E3]">  
                <mx:Spacer width="340"/>  
                <mx:Button label="确定" id="btnsave" width="68"/>  
                <mx:Button id="btnclose" click="btncloseclick()" width="64" label="离开"/>  
        </mx:ApplicationControlBar>  
    </mx:VBox>  
</mx:Module> 

顶一下
(1)
100%
踩一下
(0)
0%
loading.. 评论加载中....