home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Puzzle / Clusterz / Clusterz.swf / scripts / ENGINE / INTERFACE / OListBox.as < prev    next >
Encoding:
Text File  |  2008-09-12  |  9.9 KB  |  359 lines

  1. package ENGINE.INTERFACE
  2. {
  3.    import ENGINE.CORE.OGlobal;
  4.    import ENGINE.INTERFACE.ANIMATORS.*;
  5.    import ENGINE.INTERFACE.ELEMENTS.OListBoxElement;
  6.    import flash.events.*;
  7.    
  8.    public class OListBox extends OIObject
  9.    {
  10.       
  11.       public static const iDefAnimators:Array = [{
  12.          "F":OA_Alpha.Make,
  13.          "iSAlpha":0,
  14.          "iEAlpha":1,
  15.          "iPIter":6
  16.       },{
  17.          "F":OA_Alpha.Make,
  18.          "iSAlpha":-1,
  19.          "iEAlpha":0,
  20.          "iPIter":6
  21.       },{
  22.          "F":OA_Alpha.Make,
  23.          "iSAlpha":-1,
  24.          "iEAlpha":1,
  25.          "iPIter":6
  26.       },{
  27.          "F":OA_Alpha.Make,
  28.          "iSAlpha":-1,
  29.          "iEAlpha":0.2,
  30.          "iPIter":6
  31.       },null,null,{
  32.          "F":OA_AlphaInd.Make,
  33.          "iSAlpha":-1,
  34.          "iEAlpha":0.6,
  35.          "iInd":[0],
  36.          "iPIter":6
  37.       },{
  38.          "F":OA_AlphaInd.Make,
  39.          "iSAlpha":-1,
  40.          "iEAlpha":1,
  41.          "iInd":[0],
  42.          "iPIter":6
  43.       },null,null];
  44.        
  45.       
  46.       private var iLBParams:Array;
  47.       
  48.       private var iEGenP:Function;
  49.       
  50.       private var iElements:Array;
  51.       
  52.       public var iDown:OButton;
  53.       
  54.       private var iEGen:Array;
  55.       
  56.       public var iUp:OButton;
  57.       
  58.       private var iEShowInd:int;
  59.       
  60.       private var iSelection:Boolean = true;
  61.       
  62.       private var iECoord:Array;
  63.       
  64.       private var iECount:int;
  65.       
  66.       private var iCycling:Boolean;
  67.       
  68.       private var iECurInd:int;
  69.       
  70.       private var iPageScrool:Boolean;
  71.       
  72.       public function OListBox(param1:Array, param2:Array, param3:Function, param4:Array, param5:Array, param6:Array = null)
  73.       {
  74.          var _loc7_:Array = null;
  75.          iSelection = true;
  76.          _loc7_ = !!param6 ? param6 : iDefAnimators;
  77.          this.iEGen = param2;
  78.          this.iEGenP = param3;
  79.          this.iECoord = param4;
  80.          this.iLBParams = param5;
  81.          this.iECount = this.iECoord.length;
  82.          super(param1,_loc7_);
  83.       }
  84.       
  85.       public function SetCurrentElement(param1:*, param2:Array = null) : void
  86.       {
  87.          var _loc3_:int = 0;
  88.          if(!param1 && !param2)
  89.          {
  90.             this.FreeElements();
  91.             this.iLBParams = null;
  92.             this.iECurInd = 0;
  93.             this.iEShowInd = 0;
  94.             return;
  95.          }
  96.          if(param2)
  97.          {
  98.             this.iLBParams = param2;
  99.          }
  100.          if(!this.iLBParams)
  101.          {
  102.             return;
  103.          }
  104.          this.iECurInd = 0;
  105.          _loc3_ = 0;
  106.          while(_loc3_ < this.iLBParams.length)
  107.          {
  108.             if(param1 == this.iLBParams[_loc3_])
  109.             {
  110.                this.iECurInd = _loc3_;
  111.                break;
  112.             }
  113.             _loc3_++;
  114.          }
  115.          this.iEShowInd = this.iECurInd;
  116.          if(this.iEShowInd + this.iECount >= this.iLBParams.length)
  117.          {
  118.             this.iEShowInd = this.iLBParams.length - this.iECount;
  119.          }
  120.          if(this.iEShowInd < 0)
  121.          {
  122.             this.iEShowInd = 0;
  123.          }
  124.          InitElements();
  125.       }
  126.       
  127.       protected function UnpressElements(param1:OListBoxElement) : void
  128.       {
  129.          var _loc2_:int = 0;
  130.          _loc2_ = 0;
  131.          while(_loc2_ < this.iElements.length)
  132.          {
  133.             if(this.iElements[_loc2_])
  134.             {
  135.                if(this.iElements[_loc2_] == param1)
  136.                {
  137.                   this.iECurInd = this.iEShowInd + _loc2_;
  138.                }
  139.                else if(this.iElements[_loc2_].prPress)
  140.                {
  141.                   this.iElements[_loc2_].prPress = false;
  142.                }
  143.             }
  144.             _loc2_++;
  145.          }
  146.       }
  147.       
  148.       public function get prPageScrool() : Boolean
  149.       {
  150.          return this.iPageScrool;
  151.       }
  152.       
  153.       protected function InitElements() : void
  154.       {
  155.          var _loc1_:int = 0;
  156.          var _loc2_:int = 0;
  157.          var _loc3_:int = 0;
  158.          var _loc4_:Boolean = false;
  159.          this.FreeElements();
  160.          if(this.iLBParams == null)
  161.          {
  162.             return;
  163.          }
  164.          _loc1_ = 0;
  165.          _loc2_ = this.iEShowInd + this.iECount <= this.iLBParams.length ? this.iEShowInd + this.iECount : int(this.iLBParams.length);
  166.          _loc3_ = this.iEShowInd;
  167.          while(_loc3_ < _loc2_)
  168.          {
  169.             this.iEGenP(this.iEGen,this.iLBParams[_loc3_]);
  170.             this.iElements[_loc1_] = this.iEGen[0](this.iEGen);
  171.             this.iElements[_loc1_].Pos(OGlobal.ScaleFloor(this.iECoord[_loc1_][0]),OGlobal.ScaleFloor(this.iECoord[_loc1_][1]));
  172.             this.iElements[_loc1_].mouseEnabled = this.iSelection;
  173.             this.addChild(this.iElements[_loc1_]);
  174.             if(this.iECurInd == _loc3_ && this.iSelection)
  175.             {
  176.                this.iElements[_loc1_].prPress = true;
  177.             }
  178.             _loc1_++;
  179.             _loc3_++;
  180.          }
  181.          if(Boolean(this.iUp) && Boolean(this.iDown))
  182.          {
  183.             if(this.iCycling)
  184.             {
  185.                _loc4_ = !!this.iLBParams ? this.iLBParams.length > this.iECount : false;
  186.                if(this.iUp.prVisible != _loc4_)
  187.                {
  188.                   this.iUp.prVisible = _loc4_;
  189.                }
  190.                if(this.iDown.prVisible != _loc4_)
  191.                {
  192.                   this.iDown.prVisible = _loc4_;
  193.                }
  194.             }
  195.             else
  196.             {
  197.                if(this.iEShowInd == 0 && this.iUp.prVisible)
  198.                {
  199.                   if(this.iUp.prPress)
  200.                   {
  201.                      this.iUp.prPress = false;
  202.                   }
  203.                   this.iUp.prVisible = false;
  204.                }
  205.                if(this.iEShowInd > 0 && !this.iUp.prVisible)
  206.                {
  207.                   this.iUp.prVisible = true;
  208.                }
  209.                if(this.iEShowInd + this.iECount >= this.iLBParams.length && this.iDown.prVisible)
  210.                {
  211.                   if(this.iDown.prPress)
  212.                   {
  213.                      this.iDown.prPress = false;
  214.                   }
  215.                   this.iDown.prVisible = false;
  216.                }
  217.                if(this.iEShowInd + this.iECount < this.iLBParams.length && !this.iDown.prVisible)
  218.                {
  219.                   this.iDown.prVisible = true;
  220.                }
  221.             }
  222.          }
  223.       }
  224.       
  225.       public function set prPageScrool(param1:Boolean) : void
  226.       {
  227.          this.iPageScrool = param1;
  228.       }
  229.       
  230.       override public function Free() : void
  231.       {
  232.          this.iUp = null;
  233.          this.iDown = null;
  234.          this.iElements = null;
  235.          super.Free();
  236.       }
  237.       
  238.       public function set prCurrentInd(param1:int) : void
  239.       {
  240.          if(!this.iLBParams)
  241.          {
  242.             return;
  243.          }
  244.          this.SetCurrentElement(this.iLBParams[param1]);
  245.       }
  246.       
  247.       override public function Init() : void
  248.       {
  249.          super.Init();
  250.          this.iElements = new Array();
  251.          this.InitElements();
  252.       }
  253.       
  254.       public function set prLBParams(param1:Array) : void
  255.       {
  256.          this.iLBParams = param1;
  257.          this.iECurInd = 0;
  258.          this.iEShowInd = 0;
  259.          this.InitElements();
  260.       }
  261.       
  262.       public function get prCurrentInd() : int
  263.       {
  264.          return this.iECurInd;
  265.       }
  266.       
  267.       public function set prSelection(param1:Boolean) : void
  268.       {
  269.          this.iSelection = param1;
  270.          InitElements();
  271.       }
  272.       
  273.       public function set prCycling(param1:Boolean) : void
  274.       {
  275.          this.iCycling = param1;
  276.          InitElements();
  277.       }
  278.       
  279.       override public function OnPress(param1:Event, param2:*) : void
  280.       {
  281.          if(param2 is OListBoxElement)
  282.          {
  283.             this.UnpressElements(param2 as OListBoxElement);
  284.          }
  285.          if(param2 == this.iUp && this.SkipElements(this.iPageScrool ? int(-this.iECount) : -1))
  286.          {
  287.             this.InitElements();
  288.          }
  289.          if(param2 == this.iDown && this.SkipElements(this.iPageScrool ? this.iECount : 1))
  290.          {
  291.             this.InitElements();
  292.          }
  293.          if(this.parent is OIObject)
  294.          {
  295.             (this.parent as OIObject).OnPress(param1,this);
  296.          }
  297.       }
  298.       
  299.       public function get prSelection() : Boolean
  300.       {
  301.          return this.iSelection;
  302.       }
  303.       
  304.       protected function FreeElements() : void
  305.       {
  306.          var _loc1_:int = 0;
  307.          _loc1_ = 0;
  308.          while(_loc1_ < this.iElements.length)
  309.          {
  310.             if(this.iElements[_loc1_])
  311.             {
  312.                this.removeChild(this.iElements[_loc1_]);
  313.                this.iElements[_loc1_].Free();
  314.                this.iElements[_loc1_] = null;
  315.             }
  316.             _loc1_++;
  317.          }
  318.       }
  319.       
  320.       protected function SkipElements(param1:int) : Boolean
  321.       {
  322.          var _loc2_:int = 0;
  323.          if(!this.iLBParams)
  324.          {
  325.             return false;
  326.          }
  327.          _loc2_ = this.iEShowInd + param1;
  328.          if(_loc2_ + this.iECount >= this.iLBParams.length)
  329.          {
  330.             _loc2_ = this.iCycling ? _loc2_ - this.iLBParams.length : this.iLBParams.length - this.iECount;
  331.          }
  332.          if(_loc2_ < 0)
  333.          {
  334.             _loc2_ = this.iCycling ? this.iLBParams.length + _loc2_ : 0;
  335.          }
  336.          if(this.iEShowInd == _loc2_)
  337.          {
  338.             return false;
  339.          }
  340.          this.iEShowInd = _loc2_;
  341.          if(!this.iSelection)
  342.          {
  343.             this.iECurInd = this.iEShowInd;
  344.          }
  345.          return true;
  346.       }
  347.       
  348.       public function get prCurrentLBParam() : *
  349.       {
  350.          return !!this.iLBParams ? this.iLBParams[this.iECurInd] : null;
  351.       }
  352.       
  353.       public function get prCycling() : Boolean
  354.       {
  355.          return this.iCycling;
  356.       }
  357.    }
  358. }
  359.