home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / mx / controls / RadioButtonGroup.as < prev    next >
Encoding:
Text File  |  2010-06-23  |  7.3 KB  |  261 lines

  1. package mx.controls
  2. {
  3.    import flash.events.Event;
  4.    import flash.events.EventDispatcher;
  5.    import mx.core.Application;
  6.    import mx.core.IFlexDisplayObject;
  7.    import mx.core.IMXMLObject;
  8.    import mx.core.mx_internal;
  9.    import mx.events.FlexEvent;
  10.    
  11.    use namespace mx_internal;
  12.    
  13.    public class RadioButtonGroup extends EventDispatcher implements IMXMLObject
  14.    {
  15.       mx_internal static const VERSION:String = "3.5.0.12683";
  16.       
  17.       private var radioButtons:Array = [];
  18.       
  19.       private var _selection:RadioButton;
  20.       
  21.       private var _selectedValue:Object;
  22.       
  23.       private var document:IFlexDisplayObject;
  24.       
  25.       private var _labelPlacement:String = "right";
  26.       
  27.       private var indexNumber:int = 0;
  28.       
  29.       public function RadioButtonGroup(param1:IFlexDisplayObject = null)
  30.       {
  31.          super();
  32.       }
  33.       
  34.       [Bindable("enabledChanged")]
  35.       public function get enabled() : Boolean
  36.       {
  37.          var _loc1_:Number = 0;
  38.          var _loc2_:int = numRadioButtons;
  39.          var _loc3_:int = 0;
  40.          while(_loc3_ < _loc2_)
  41.          {
  42.             _loc1_ += getRadioButtonAt(_loc3_).enabled;
  43.             _loc3_++;
  44.          }
  45.          if(_loc1_ == 0)
  46.          {
  47.             return false;
  48.          }
  49.          if(_loc1_ == _loc2_)
  50.          {
  51.             return true;
  52.          }
  53.          return false;
  54.       }
  55.       
  56.       public function set enabled(param1:Boolean) : void
  57.       {
  58.          var _loc2_:int = numRadioButtons;
  59.          var _loc3_:int = 0;
  60.          while(_loc3_ < _loc2_)
  61.          {
  62.             getRadioButtonAt(_loc3_).enabled = param1;
  63.             _loc3_++;
  64.          }
  65.          dispatchEvent(new Event("enabledChanged"));
  66.       }
  67.       
  68.       private function radioButton_removedHandler(param1:Event) : void
  69.       {
  70.          var _loc2_:RadioButton = param1.target as RadioButton;
  71.          if(_loc2_)
  72.          {
  73.             _loc2_.removeEventListener(Event.REMOVED,radioButton_removedHandler);
  74.             mx_internal::removeInstance(RadioButton(param1.target));
  75.          }
  76.       }
  77.       
  78.       public function set selectedValue(param1:Object) : void
  79.       {
  80.          var _loc4_:RadioButton = null;
  81.          _selectedValue = param1;
  82.          var _loc2_:int = numRadioButtons;
  83.          var _loc3_:int = 0;
  84.          while(_loc3_ < _loc2_)
  85.          {
  86.             _loc4_ = getRadioButtonAt(_loc3_);
  87.             if(_loc4_.value == param1 || _loc4_.label == param1)
  88.             {
  89.                changeSelection(_loc3_,false);
  90.                break;
  91.             }
  92.             _loc3_++;
  93.          }
  94.          dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
  95.       }
  96.       
  97.       private function getValue() : String
  98.       {
  99.          if(selection)
  100.          {
  101.             return selection.value && selection.value is String && String(selection.value).length != 0 ? String(selection.value) : selection.label;
  102.          }
  103.          return null;
  104.       }
  105.       
  106.       [Bindable("labelPlacementChanged")]
  107.       public function get labelPlacement() : String
  108.       {
  109.          return _labelPlacement;
  110.       }
  111.       
  112.       [Bindable("valueCommit")]
  113.       [Bindable("change")]
  114.       public function get selection() : RadioButton
  115.       {
  116.          return _selection;
  117.       }
  118.       
  119.       [Bindable("valueCommit")]
  120.       [Bindable("change")]
  121.       public function get selectedValue() : Object
  122.       {
  123.          if(selection)
  124.          {
  125.             return selection.value != null ? selection.value : selection.label;
  126.          }
  127.          return null;
  128.       }
  129.       
  130.       public function set selection(param1:RadioButton) : void
  131.       {
  132.          mx_internal::setSelection(param1,false);
  133.       }
  134.       
  135.       mx_internal function setSelection(param1:RadioButton, param2:Boolean = true) : void
  136.       {
  137.          var _loc3_:int = 0;
  138.          var _loc4_:int = 0;
  139.          if(param1 == null && _selection != null)
  140.          {
  141.             _selection.selected = false;
  142.             _selection = null;
  143.             if(param2)
  144.             {
  145.                dispatchEvent(new Event(Event.CHANGE));
  146.             }
  147.          }
  148.          else
  149.          {
  150.             _loc3_ = numRadioButtons;
  151.             _loc4_ = 0;
  152.             while(_loc4_ < _loc3_)
  153.             {
  154.                if(param1 == getRadioButtonAt(_loc4_))
  155.                {
  156.                   changeSelection(_loc4_,param2);
  157.                   break;
  158.                }
  159.                _loc4_++;
  160.             }
  161.          }
  162.          dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
  163.       }
  164.       
  165.       public function initialized(param1:Object, param2:String) : void
  166.       {
  167.          this.document = !!param1 ? IFlexDisplayObject(param1) : IFlexDisplayObject(Application.application);
  168.       }
  169.       
  170.       mx_internal function addInstance(param1:RadioButton) : void
  171.       {
  172.          param1.mx_internal::indexNumber = indexNumber++;
  173.          param1.addEventListener(Event.REMOVED,radioButton_removedHandler);
  174.          radioButtons.push(param1);
  175.          if(_selectedValue != null)
  176.          {
  177.             selectedValue = _selectedValue;
  178.          }
  179.          dispatchEvent(new Event("numRadioButtonsChanged"));
  180.       }
  181.       
  182.       public function set labelPlacement(param1:String) : void
  183.       {
  184.          _labelPlacement = param1;
  185.          var _loc2_:int = numRadioButtons;
  186.          var _loc3_:int = 0;
  187.          while(_loc3_ < _loc2_)
  188.          {
  189.             getRadioButtonAt(_loc3_).labelPlacement = param1;
  190.             _loc3_++;
  191.          }
  192.       }
  193.       
  194.       [Bindable("numRadioButtonsChanged")]
  195.       public function get numRadioButtons() : int
  196.       {
  197.          return radioButtons.length;
  198.       }
  199.       
  200.       public function getRadioButtonAt(param1:int) : RadioButton
  201.       {
  202.          return RadioButton(radioButtons[param1]);
  203.       }
  204.       
  205.       mx_internal function removeInstance(param1:RadioButton) : void
  206.       {
  207.          var _loc2_:Boolean = false;
  208.          var _loc3_:int = 0;
  209.          var _loc4_:RadioButton = null;
  210.          if(param1)
  211.          {
  212.             _loc2_ = false;
  213.             _loc3_ = 0;
  214.             while(_loc3_ < numRadioButtons)
  215.             {
  216.                _loc4_ = getRadioButtonAt(_loc3_);
  217.                if(_loc2_)
  218.                {
  219.                   --_loc4_.mx_internal::indexNumber;
  220.                }
  221.                else if(_loc4_ == param1)
  222.                {
  223.                   _loc4_.group = null;
  224.                   if(param1 == _selection)
  225.                   {
  226.                      _selection = null;
  227.                   }
  228.                   radioButtons.splice(_loc3_,1);
  229.                   _loc2_ = true;
  230.                   --indexNumber;
  231.                   _loc3_--;
  232.                }
  233.                _loc3_++;
  234.             }
  235.             if(_loc2_)
  236.             {
  237.                dispatchEvent(new Event("numRadioButtonsChanged"));
  238.             }
  239.          }
  240.       }
  241.       
  242.       private function changeSelection(param1:int, param2:Boolean = true) : void
  243.       {
  244.          if(getRadioButtonAt(param1))
  245.          {
  246.             if(selection)
  247.             {
  248.                selection.selected = false;
  249.             }
  250.             _selection = getRadioButtonAt(param1);
  251.             _selection.selected = true;
  252.             if(param2)
  253.             {
  254.                dispatchEvent(new Event(Event.CHANGE));
  255.             }
  256.          }
  257.       }
  258.    }
  259. }
  260.  
  261.