eduardosavoine

myDropDownList.as

Sep 19th, 2011
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package components
  2. {
  3.     import mx.collections.IList;
  4.     import mx.controls.Alert;
  5.     import mx.utils.ObjectUtil;
  6.    
  7.     import spark.components.DropDownList;
  8.    
  9.     public class myDropDownList extends DropDownList
  10.     {
  11.         public function myDropDownList()
  12.         {
  13.             super();
  14.         }
  15.        
  16.         [Bindable]
  17.         private var _textField:*;              
  18.        
  19.         [Bindable]
  20.         public function get textField():*
  21.         {
  22.             return _textField;
  23.         }
  24.  
  25.         public function set textField(value:*):void
  26.         {
  27.             textField = this.getListValue(value);
  28.         }
  29.  
  30.         private function getListValue(value:*):*
  31.         {          
  32.             if (value == null)
  33.             {
  34.                 selectedIndex = -1;
  35.                 return;
  36.             }
  37.             for each (var obj:Object in dataProvider)
  38.             {              
  39.                 if (ObjectUtil.compare(obj.cCdId.toString(), value) == 0)
  40.                 {
  41.                     super.selectedIndex = dataProvider.getItemIndex(obj);
  42.                     return value;
  43.                 }              
  44.             }
  45.             return value;
  46.         }  
  47.        
  48.         override public function set dataProvider(value:IList): void
  49.         {
  50.             super.dataProvider = value;
  51.             if (selectedItem != null)
  52.             {
  53.                 textField = this.getListValue(selectedItem.cCdId);
  54.             }
  55.         }
  56.  
  57. /*** Versão do Bruno (DCLICK)
  58.         private function getListValue(value:*):*
  59.         {          
  60.             if (value == null)
  61.             {
  62.                 selectedIndex = -1;
  63.                 return;
  64.             }
  65.             for each (var obj:Object in dataProvider)
  66.             {              
  67.                 if (ObjectUtil.compare(obj, value) == 0)
  68.                 {
  69.                     return obj;
  70.                 }              
  71.             }
  72.             return value;
  73.         }
  74.    
  75.         override public function set selectedItem(value:*): void
  76.         {
  77.             super.selectedItem = this.getListValue(value);
  78.         }
  79.        
  80.         override public function set dataProvider(value:IList): void
  81.         {
  82.             super.dataProvider = value;
  83.             if (selectedItem != null)
  84.             {
  85.                 super.selectedItem = this.getListValue(selectedItem);
  86.             }
  87.         }  
  88.          
  89. ***/   
  90.     }      
  91. }
Advertisement
Add Comment
Please, Sign In to add comment