ComboBox

代码
<? xml version = " 1.0 "  encoding = " utf-8 " ?>  
< mx:Application xmlns:mx = " http://www.adobe.com/2006/mxml "  layout = " absolute "  creationComplete = " initCB(); "  width = " 283 "  height = " 102 " >  
 
< mx:Style >  
  global{ 
   fontSize: 12px 
  } 
 
< / mx:Style> 
  < mx:Script >  
  
<! [CDATA[ 
   private 
function  initCB(): void
    
var  info:Array  =   new  Array(); 
    info.push({label:
" B1 " , data: " 3 " }); 
    info.push({label:
" B2 " , data: " 2 " }); 
    
this .cb1.dataProvider  =  info; 
   } 

   private 
function  setCB1Index(): void {    // 根据值查询数据,如:数据来自库文件 
     for  each( var  obj:Object  in  cb1.dataProvider){ 
     
if (obj.data == edit_txt.text){ 
      cb1.selectedItem
= obj; 
      
break
     } 
    } 
//     cb1.selectedIndex=0;      //数据固定,已经知道序号 
   } 
  ]]
>  
 
< / mx:Script>    
  < mx:ComboBox x = " 25.5 "  y = " 24 "  id = " cb1 " >< / mx:ComboBox> 
  < mx:TextInput x = " 25.5 "  y = " 56 "  id = " edit_txt "/
  < mx:Button x = " 193.5 "  y = " 55 "  label = " Click "  click = " setCB1Index(); "/
< / mx:Application> 

 

你可能感兴趣的:(combobox)