home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / com / Rating / Ratings.as < prev   
Encoding:
Text File  |  2010-06-23  |  10.8 KB  |  372 lines

  1. package com.Rating
  2. {
  3.    import flash.events.Event;
  4.    import flash.events.MouseEvent;
  5.    import mx.controls.dataGridClasses.DataGridListData;
  6.    import mx.controls.listClasses.BaseListData;
  7.    import mx.controls.listClasses.IDropInListItemRenderer;
  8.    import mx.controls.listClasses.IListItemRenderer;
  9.    import mx.core.IDataRenderer;
  10.    import mx.core.UIComponent;
  11.    import mx.events.FlexEvent;
  12.    import mx.events.PropertyChangeEvent;
  13.    
  14.    public class Ratings extends UIComponent implements IDataRenderer, IDropInListItemRenderer, IListItemRenderer
  15.    {
  16.       private var _data:Object;
  17.       
  18.       private var _1249874743_innerRadius:Number = 25;
  19.       
  20.       private const itemCount:Number = 5;
  21.       
  22.       private var _1725716994_points:Number = 5;
  23.       
  24.       private var _listData:BaseListData;
  25.       
  26.       private var contentWidth:Number = 0;
  27.       
  28.       private var _892116433_tooltips:Array = null;
  29.       
  30.       [Bindable(event="change")]
  31.       private var _value:int = 0;
  32.       
  33.       private var _1482236972_angle:Number = 90;
  34.       
  35.       private var _1517899566_outerRadius:Number = 50;
  36.       
  37.       public function Ratings()
  38.       {
  39.          super();
  40.          addEventListener(MouseEvent.MOUSE_OUT,this.handleMouseOut);
  41.          addEventListener(MouseEvent.ROLL_OUT,this.handleMouseOut);
  42.          mouseChildren = true;
  43.       }
  44.       
  45.       [Bindable(event="propertyChange")]
  46.       private function get _points() : Number
  47.       {
  48.          return this._1725716994_points;
  49.       }
  50.       
  51.       public function get innerRadius() : Number
  52.       {
  53.          return this._innerRadius;
  54.       }
  55.       
  56.       private function set _points(param1:Number) : void
  57.       {
  58.          var _loc2_:Object = this._1725716994_points;
  59.          if(_loc2_ !== param1)
  60.          {
  61.             this._1725716994_points = param1;
  62.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"_points",_loc2_,param1));
  63.          }
  64.       }
  65.       
  66.       public function set innerRadius(param1:Number) : void
  67.       {
  68.          this._innerRadius = param1;
  69.          this.updateChildren("innerRadius",param1);
  70.       }
  71.       
  72.       private function set _innerRadius(param1:Number) : void
  73.       {
  74.          var _loc2_:Object = this._1249874743_innerRadius;
  75.          if(_loc2_ !== param1)
  76.          {
  77.             this._1249874743_innerRadius = param1;
  78.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"_innerRadius",_loc2_,param1));
  79.          }
  80.       }
  81.       
  82.       public function set tooltips(param1:Array) : void
  83.       {
  84.          this._tooltips = param1;
  85.       }
  86.       
  87.       private function selectItems(param1:Number) : void
  88.       {
  89.          var _loc2_:RatingItem = null;
  90.          var _loc3_:int = 1;
  91.          while(_loc3_ < this.itemCount + 1)
  92.          {
  93.             _loc2_ = RatingItem(getChildByName(_loc3_.toString()));
  94.             if(_loc2_)
  95.             {
  96.                if(_loc3_ <= param1)
  97.                {
  98.                   _loc2_.selected = true;
  99.                }
  100.                else
  101.                {
  102.                   _loc2_.selected = false;
  103.                }
  104.             }
  105.             _loc3_++;
  106.          }
  107.       }
  108.       
  109.       public function set angle(param1:Number) : void
  110.       {
  111.          this._angle = param1;
  112.          this.updateChildren("angle",param1);
  113.       }
  114.       
  115.       private function set _angle(param1:Number) : void
  116.       {
  117.          var _loc2_:Object = this._1482236972_angle;
  118.          if(_loc2_ !== param1)
  119.          {
  120.             this._1482236972_angle = param1;
  121.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"_angle",_loc2_,param1));
  122.          }
  123.       }
  124.       
  125.       [Bindable("dataChange")]
  126.       public function get data() : Object
  127.       {
  128.          return this._data;
  129.       }
  130.       
  131.       [Bindable(event="propertyChange")]
  132.       private function get _outerRadius() : Number
  133.       {
  134.          return this._1517899566_outerRadius;
  135.       }
  136.       
  137.       [Bindable(event="propertyChange")]
  138.       private function get _tooltips() : Array
  139.       {
  140.          return this._892116433_tooltips;
  141.       }
  142.       
  143.       private function handleMouseOut(param1:MouseEvent) : void
  144.       {
  145.          if(param1.currentTarget is Ratings)
  146.          {
  147.             this.selectItems(this.value);
  148.          }
  149.       }
  150.       
  151.       public function set points(param1:Number) : void
  152.       {
  153.          this._points = param1;
  154.          this.updateChildren("points",param1);
  155.       }
  156.       
  157.       [Bindable(event="propertyChange")]
  158.       private function get _innerRadius() : Number
  159.       {
  160.          return this._1249874743_innerRadius;
  161.       }
  162.       
  163.       public function set listData(param1:BaseListData) : void
  164.       {
  165.          this._listData = param1;
  166.       }
  167.       
  168.       public function get angle() : Number
  169.       {
  170.          return this._angle;
  171.       }
  172.       
  173.       public function set data(param1:Object) : void
  174.       {
  175.          var value:Object = param1;
  176.          this._data = value;
  177.          try
  178.          {
  179.             if(Boolean(this._listData) && this._listData is DataGridListData)
  180.             {
  181.                this.value = this._data[DataGridListData(this._listData).dataField];
  182.             }
  183.             else
  184.             {
  185.                this.value = int(this._listData.label);
  186.             }
  187.          }
  188.          catch(e:Error)
  189.          {
  190.             this.value = 0;
  191.          }
  192.          dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
  193.       }
  194.       
  195.       public function set outerRadius(param1:Number) : void
  196.       {
  197.          this._outerRadius = param1;
  198.          this.updateChildren("outerRadius",param1);
  199.       }
  200.       
  201.       private function set _outerRadius(param1:Number) : void
  202.       {
  203.          var _loc2_:Object = this._1517899566_outerRadius;
  204.          if(_loc2_ !== param1)
  205.          {
  206.             this._1517899566_outerRadius = param1;
  207.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"_outerRadius",_loc2_,param1));
  208.          }
  209.       }
  210.       
  211.       private function set _tooltips(param1:Array) : void
  212.       {
  213.          var _loc2_:Object = this._892116433_tooltips;
  214.          if(_loc2_ !== param1)
  215.          {
  216.             this._892116433_tooltips = param1;
  217.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"_tooltips",_loc2_,param1));
  218.          }
  219.       }
  220.       
  221.       public function get tooltips() : Array
  222.       {
  223.          return this._tooltips;
  224.       }
  225.       
  226.       public function set value(param1:int) : void
  227.       {
  228.          var value:int = param1;
  229.          this._value = value;
  230.          this.selectItems(value);
  231.          try
  232.          {
  233.             if(Boolean(this._listData) && this._listData is DataGridListData)
  234.             {
  235.                this._data[DataGridListData(this._listData).dataField] = this._value;
  236.             }
  237.             else
  238.             {
  239.                this._listData.label = this._value.toString();
  240.             }
  241.          }
  242.          catch(e:Error)
  243.          {
  244.          }
  245.          dispatchEvent(new Event("change"));
  246.       }
  247.       
  248.       public function get points() : Number
  249.       {
  250.          return this._points;
  251.       }
  252.       
  253.       private function updateChildren(param1:String, param2:Number) : void
  254.       {
  255.          var _loc3_:int = 1;
  256.          while(_loc3_ < this.itemCount + 1)
  257.          {
  258.             if(getChildByName(_loc3_.toString()))
  259.             {
  260.                RatingItem(getChildByName(_loc3_.toString()))[param1] = param2;
  261.             }
  262.             _loc3_++;
  263.          }
  264.       }
  265.       
  266.       override protected function childrenCreated() : void
  267.       {
  268.          var _loc6_:RatingItem = null;
  269.          var _loc1_:Number = getStyle("horizontalGap");
  270.          var _loc2_:Number = getStyle("paddingLeft");
  271.          var _loc3_:Number = getStyle("paddingTop");
  272.          var _loc4_:Number = 0;
  273.          var _loc5_:int = 1;
  274.          while(_loc5_ < this.itemCount + 1)
  275.          {
  276.             _loc6_ = new RatingItem();
  277.             _loc6_.id = _loc5_.toString();
  278.             _loc6_.name = _loc5_.toString();
  279.             _loc6_.setStyle("borderAlpha",0);
  280.             _loc6_.setStyle("fillEnabled",true);
  281.             _loc6_.setStyle("fillColors",[3355443,13421772]);
  282.             _loc6_.setStyle("fillSelectedColors",[16737792,16777164]);
  283.             _loc6_.setStyle("fillAlphas",[1,1]);
  284.             _loc6_.setStyle("fillRatios",[0,255]);
  285.             _loc6_.setStyle("fillAngle",90);
  286.             if(this.tooltips)
  287.             {
  288.                if(this.tooltips.length > _loc5_ - 1)
  289.                {
  290.                   _loc6_.toolTip = this.tooltips[_loc5_ - 1].toString();
  291.                }
  292.             }
  293.             _loc6_.width = 12;
  294.             _loc6_.height = 12;
  295.             addChild(_loc6_);
  296.             if(_loc4_ == 0)
  297.             {
  298.                _loc6_.x = _loc2_;
  299.             }
  300.             else
  301.             {
  302.                _loc6_.x = 12 + _loc1_ + _loc4_;
  303.             }
  304.             _loc4_ = _loc6_.x;
  305.             _loc6_.y = _loc3_;
  306.             if(_loc5_ - 1 < this.value)
  307.             {
  308.                _loc6_.selected = true;
  309.             }
  310.             _loc6_.addEventListener(MouseEvent.CLICK,this.handleItemClick,false,1);
  311.             _loc6_.addEventListener(MouseEvent.ROLL_OVER,this.handleMouseRoll);
  312.             _loc6_.addEventListener(MouseEvent.ROLL_OUT,this.handleMouseRoll);
  313.             _loc5_++;
  314.          }
  315.          width = _loc6_.x + _loc1_;
  316.          height = 12;
  317.       }
  318.       
  319.       [Bindable(event="propertyChange")]
  320.       private function get _angle() : Number
  321.       {
  322.          return this._1482236972_angle;
  323.       }
  324.       
  325.       private function handleItemClick(param1:MouseEvent) : void
  326.       {
  327.          param1.preventDefault();
  328.          param1.stopImmediatePropagation();
  329.          if(param1.currentTarget.id == 1 && this.value == 1)
  330.          {
  331.             this.value = 0;
  332.          }
  333.          else
  334.          {
  335.             this.value = Number(param1.currentTarget.id);
  336.          }
  337.          dispatchEvent(param1);
  338.       }
  339.       
  340.       [Bindable("dataChange")]
  341.       public function get listData() : BaseListData
  342.       {
  343.          return this._listData;
  344.       }
  345.       
  346.       public function get value() : int
  347.       {
  348.          return this._value;
  349.       }
  350.       
  351.       public function get outerRadius() : Number
  352.       {
  353.          return this._outerRadius;
  354.       }
  355.       
  356.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  357.       {
  358.          super.updateDisplayList(param1,param2);
  359.          graphics.lineStyle(0,16777215,0);
  360.          graphics.beginFill(16777215,0);
  361.          graphics.drawRect(0,0,param1,param2);
  362.          graphics.endFill();
  363.       }
  364.       
  365.       private function handleMouseRoll(param1:MouseEvent) : void
  366.       {
  367.          this.selectItems(Number(param1.currentTarget.name));
  368.       }
  369.    }
  370. }
  371.  
  372.