home *** CD-ROM | disk | FTP | other *** search
/ Champak 114 / Vol 114.iso / games / park_thi.swf / scripts / __Packages / mx / controls / ComboBox.as < prev    next >
Encoding:
Text File  |  2010-08-12  |  15.2 KB  |  534 lines

  1. class mx.controls.ComboBox extends mx.controls.ComboBase
  2. {
  3.    var editable;
  4.    var __labels;
  5.    var data;
  6.    var __dropdownWidth;
  7.    var __width;
  8.    var selectedIndex;
  9.    var __dropdown;
  10.    var dataProvider;
  11.    var __labelFunction;
  12.    var owner;
  13.    var mask;
  14.    var border_mc;
  15.    var text_mc;
  16.    var getValue;
  17.    var length;
  18.    var selectedItem;
  19.    var isPressed;
  20.    var height;
  21.    var __selectedIndexOnDropdown;
  22.    var __initialSelectedIndexOnDropdown;
  23.    var rowCount;
  24.    var width;
  25.    var __dataProvider;
  26.    var selected;
  27.    var dispatchEvent;
  28.    static var symbolName = "ComboBox";
  29.    static var symbolOwner = mx.controls.ComboBox;
  30.    static var version = "2.0.2.126";
  31.    var clipParameters = {labels:1,data:1,editable:1,rowCount:1,dropdownWidth:1};
  32.    static var mergedClipParameters = mx.core.UIObject.mergeClipParameters(mx.controls.ComboBox.prototype.clipParameters,mx.controls.ComboBase.prototype.clipParameters);
  33.    var className = "ComboBox";
  34.    var _showingDropdown = false;
  35.    var __rowCount = 5;
  36.    var dropdownBorderStyle = undefined;
  37.    var initializing = true;
  38.    var __labelField = "label";
  39.    var bInKeyDown = false;
  40.    function ComboBox()
  41.    {
  42.       super();
  43.    }
  44.    function init()
  45.    {
  46.       super.init();
  47.    }
  48.    function createChildren()
  49.    {
  50.       super.createChildren();
  51.       this.editable = this.editable;
  52.       if(this.__labels.length > 0)
  53.       {
  54.          var _loc6_ = new Array();
  55.          var _loc3_ = 0;
  56.          while(_loc3_ < this.labels.length)
  57.          {
  58.             _loc6_.addItem({label:this.labels[_loc3_],data:this.data[_loc3_]});
  59.             _loc3_ = _loc3_ + 1;
  60.          }
  61.          this.setDataProvider(_loc6_);
  62.       }
  63.       this.dropdownWidth = typeof this.__dropdownWidth != "number" ? this.__width : this.__dropdownWidth;
  64.       if(!this._editable)
  65.       {
  66.          this.selectedIndex = 0;
  67.       }
  68.       this.initializing = false;
  69.    }
  70.    function onKillFocus(n)
  71.    {
  72.       if(this._showingDropdown && n != null)
  73.       {
  74.          this.displayDropdown(false);
  75.       }
  76.       super.onKillFocus();
  77.    }
  78.    function getDropdown()
  79.    {
  80.       if(this.initializing)
  81.       {
  82.          return undefined;
  83.       }
  84.       if(!this.hasDropdown())
  85.       {
  86.          var _loc3_ = new Object();
  87.          _loc3_.styleName = this;
  88.          if(this.dropdownBorderStyle != undefined)
  89.          {
  90.             _loc3_.borderStyle = this.dropdownBorderStyle;
  91.          }
  92.          _loc3_._visible = false;
  93.          this.__dropdown = mx.managers.PopUpManager.createPopUp(this,mx.controls.List,false,_loc3_,true);
  94.          this.__dropdown.scroller.mask.removeMovieClip();
  95.          if(this.dataProvider == undefined)
  96.          {
  97.             this.dataProvider = new Array();
  98.          }
  99.          this.__dropdown.setDataProvider(this.dataProvider);
  100.          this.__dropdown.selectMultiple = false;
  101.          this.__dropdown.rowCount = this.__rowCount;
  102.          this.__dropdown.selectedIndex = this.selectedIndex;
  103.          this.__dropdown.vScrollPolicy = "auto";
  104.          this.__dropdown.labelField = this.__labelField;
  105.          this.__dropdown.labelFunction = this.__labelFunction;
  106.          this.__dropdown.owner = this;
  107.          this.__dropdown.changeHandler = this._changeHandler;
  108.          this.__dropdown.scrollHandler = this._scrollHandler;
  109.          this.__dropdown.itemRollOverHandler = this._itemRollOverHandler;
  110.          this.__dropdown.itemRollOutHandler = this._itemRollOutHandler;
  111.          this.__dropdown.resizeHandler = this._resizeHandler;
  112.          this.__dropdown.mouseDownOutsideHandler = function(eventObj)
  113.          {
  114.             var _loc3_ = this.owner;
  115.             var _loc4_ = new Object();
  116.             _loc4_.x = _loc3_._root._xmouse;
  117.             _loc4_.y = _loc3_._root._ymouse;
  118.             _loc3_._root.localToGlobal(_loc4_);
  119.             if(!_loc3_.hitTest(_loc4_.x,_loc4_.y,false))
  120.             {
  121.                if(!(!this.wrapDownArrowButton && this.owner.downArrow_mc.hitTest(_root._xmouse,_root._ymouse,false)))
  122.                {
  123.                   _loc3_.displayDropdown(false);
  124.                }
  125.             }
  126.          };
  127.          this.__dropdown.onTweenUpdate = function(v)
  128.          {
  129.             this._y = v;
  130.          };
  131.          this.__dropdown.setSize(this.__dropdownWidth,this.__dropdown.height);
  132.          this.createObject("BoundingBox","mask",20);
  133.          this.mask._y = this.border_mc.height;
  134.          this.mask._width = this.__dropdownWidth;
  135.          this.mask._height = this.__dropdown.height;
  136.          this.mask._visible = false;
  137.          this.__dropdown.setMask(this.mask);
  138.       }
  139.       return this.__dropdown;
  140.    }
  141.    function setSize(w, h, noEvent)
  142.    {
  143.       super.setSize(w,h,noEvent);
  144.       this.__dropdownWidth = w;
  145.       this.__dropdown.rowHeight = h;
  146.       this.__dropdown.setSize(this.__dropdownWidth,this.__dropdown.height);
  147.    }
  148.    function setEditable(e)
  149.    {
  150.       super.setEditable(e);
  151.       if(e)
  152.       {
  153.          this.text_mc.setText("");
  154.       }
  155.       else
  156.       {
  157.          this.text_mc.setText(this.selectedLabel);
  158.       }
  159.    }
  160.    function get labels()
  161.    {
  162.       return this.__labels;
  163.    }
  164.    function set labels(lbls)
  165.    {
  166.       this.__labels = lbls;
  167.       this.setDataProvider(lbls);
  168.    }
  169.    function getLabelField()
  170.    {
  171.       return this.__labelField;
  172.    }
  173.    function get labelField()
  174.    {
  175.       return this.getLabelField();
  176.    }
  177.    function setLabelField(s)
  178.    {
  179.       this.__dropdown.labelField = this.__labelField = s;
  180.       this.text_mc.setText(this.selectedLabel);
  181.    }
  182.    function set labelField(s)
  183.    {
  184.       this.setLabelField(s);
  185.    }
  186.    function getLabelFunction()
  187.    {
  188.       return this.__labelFunction;
  189.    }
  190.    function get labelFunction()
  191.    {
  192.       return this.getLabelFunction();
  193.    }
  194.    function set labelFunction(f)
  195.    {
  196.       this.__dropdown.labelFunction = this.__labelFunction = f;
  197.       this.text_mc.setText(this.selectedLabel);
  198.    }
  199.    function setSelectedItem(v)
  200.    {
  201.       super.setSelectedItem(v);
  202.       this.__dropdown.selectedItem = v;
  203.       this.text_mc.setText(this.selectedLabel);
  204.    }
  205.    function setSelectedIndex(v)
  206.    {
  207.       super.setSelectedIndex(v);
  208.       this.__dropdown.selectedIndex = v;
  209.       if(v != undefined)
  210.       {
  211.          this.text_mc.setText(this.selectedLabel);
  212.       }
  213.       this.dispatchValueChangedEvent(this.getValue());
  214.    }
  215.    function setRowCount(count)
  216.    {
  217.       if(isNaN(count))
  218.       {
  219.          return undefined;
  220.       }
  221.       this.__rowCount = count;
  222.       this.__dropdown.setRowCount(count);
  223.    }
  224.    function get rowCount()
  225.    {
  226.       return Math.max(1,Math.min(this.length,this.__rowCount));
  227.    }
  228.    function set rowCount(v)
  229.    {
  230.       this.setRowCount(v);
  231.    }
  232.    function setDropdownWidth(w)
  233.    {
  234.       this.__dropdownWidth = w;
  235.       this.__dropdown.setSize(w,this.__dropdown.height);
  236.    }
  237.    function get dropdownWidth()
  238.    {
  239.       return this.__dropdownWidth;
  240.    }
  241.    function set dropdownWidth(v)
  242.    {
  243.       this.setDropdownWidth(v);
  244.    }
  245.    function get dropdown()
  246.    {
  247.       return this.getDropdown();
  248.    }
  249.    function setDataProvider(dp)
  250.    {
  251.       super.setDataProvider(dp);
  252.       this.__dropdown.setDataProvider(dp);
  253.       if(!this._editable)
  254.       {
  255.          this.selectedIndex = 0;
  256.       }
  257.    }
  258.    function open()
  259.    {
  260.       this.displayDropdown(true);
  261.    }
  262.    function close()
  263.    {
  264.       this.displayDropdown(false);
  265.    }
  266.    function get selectedLabel()
  267.    {
  268.       var _loc2_ = this.selectedItem;
  269.       if(_loc2_ == undefined)
  270.       {
  271.          return "";
  272.       }
  273.       if(this.labelFunction != undefined)
  274.       {
  275.          return this.labelFunction(_loc2_);
  276.       }
  277.       if(typeof _loc2_ != "object")
  278.       {
  279.          return _loc2_;
  280.       }
  281.       if(_loc2_[this.labelField] != undefined)
  282.       {
  283.          return _loc2_[this.labelField];
  284.       }
  285.       if(_loc2_.label != undefined)
  286.       {
  287.          return _loc2_.label;
  288.       }
  289.       var _loc3_ = " ";
  290.       for(var _loc4_ in _loc2_)
  291.       {
  292.          if(_loc4_ != "__ID__")
  293.          {
  294.             _loc3_ = _loc2_[_loc4_] + ", " + _loc3_;
  295.          }
  296.       }
  297.       _loc3_ = _loc3_.substring(0,_loc3_.length - 3);
  298.       return _loc3_;
  299.    }
  300.    function hasDropdown()
  301.    {
  302.       return this.__dropdown != undefined && this.__dropdown.valueOf() != undefined;
  303.    }
  304.    function tweenEndShow(value)
  305.    {
  306.       this._y = value;
  307.       this.isPressed = true;
  308.       this.owner.dispatchEvent({type:"open",target:this.owner});
  309.    }
  310.    function tweenEndHide(value)
  311.    {
  312.       this._y = value;
  313.       this.visible = false;
  314.       this.owner.dispatchEvent({type:"close",target:this.owner});
  315.    }
  316.    function displayDropdown(show)
  317.    {
  318.       if(show == this._showingDropdown)
  319.       {
  320.          return undefined;
  321.       }
  322.       var _loc3_ = new Object();
  323.       _loc3_.x = 0;
  324.       _loc3_.y = this.height;
  325.       this.localToGlobal(_loc3_);
  326.       if(show)
  327.       {
  328.          this.__selectedIndexOnDropdown = this.selectedIndex;
  329.          this.__initialSelectedIndexOnDropdown = this.selectedIndex;
  330.          this.getDropdown();
  331.          var _loc2_ = this.__dropdown;
  332.          _loc2_.isPressed = true;
  333.          _loc2_.rowCount = this.rowCount;
  334.          _loc2_.visible = show;
  335.          _loc2_._parent.globalToLocal(_loc3_);
  336.          _loc2_.onTweenEnd = this.tweenEndShow;
  337.          var _loc5_ = undefined;
  338.          var _loc8_ = undefined;
  339.          if(_loc3_.y + _loc2_.height > Stage.height)
  340.          {
  341.             _loc5_ = _loc3_.y - this.height;
  342.             _loc8_ = _loc5_ - _loc2_.height;
  343.             this.mask._y = - _loc2_.height;
  344.          }
  345.          else
  346.          {
  347.             _loc5_ = _loc3_.y - _loc2_.height;
  348.             _loc8_ = _loc3_.y;
  349.             this.mask._y = this.border_mc.height;
  350.          }
  351.          var _loc6_ = _loc2_.selectedIndex;
  352.          if(_loc6_ == undefined)
  353.          {
  354.             _loc6_ = 0;
  355.          }
  356.          var _loc4_ = _loc2_.vPosition;
  357.          _loc4_ = _loc6_ - 1;
  358.          _loc4_ = Math.min(Math.max(_loc4_,0),_loc2_.length - _loc2_.rowCount);
  359.          _loc2_.vPosition = _loc4_;
  360.          _loc2_.move(_loc3_.x,_loc5_);
  361.          _loc2_.tween = new mx.effects.Tween(this.__dropdown,_loc5_,_loc8_,this.getStyle("openDuration"));
  362.       }
  363.       else
  364.       {
  365.          this.__dropdown._parent.globalToLocal(_loc3_);
  366.          delete this.__dropdown.dragScrolling;
  367.          this.__dropdown.onTweenEnd = this.tweenEndHide;
  368.          this.__dropdown.tween = new mx.effects.Tween(this.__dropdown,this.__dropdown._y,_loc3_.y - this.__dropdown.height,this.getStyle("openDuration"));
  369.          if(this.__initialSelectedIndexOnDropdown != this.selectedIndex)
  370.          {
  371.             this.dispatchChangeEvent(undefined,this.__initialSelectedIndexOnDropdown,this.selectedIndex);
  372.          }
  373.       }
  374.       var _loc9_ = this.getStyle("openEasing");
  375.       if(_loc9_ != undefined)
  376.       {
  377.          this.__dropdown.tween.easingEquation = _loc9_;
  378.       }
  379.       this._showingDropdown = show;
  380.    }
  381.    function onDownArrow()
  382.    {
  383.       this._parent.displayDropdown(!this._parent._showingDropdown);
  384.    }
  385.    function keyDown(e)
  386.    {
  387.       if(e.ctrlKey && e.code == 40)
  388.       {
  389.          this.displayDropdown(true);
  390.       }
  391.       else if(e.ctrlKey && e.code == 38)
  392.       {
  393.          this.displayDropdown(false);
  394.          this.dispatchChangeEvent(undefined,this.__selectedIndexOnDropdown,this.selectedIndex);
  395.       }
  396.       else if(e.code == 27)
  397.       {
  398.          this.displayDropdown(false);
  399.       }
  400.       else if(e.code == 13)
  401.       {
  402.          if(this._showingDropdown)
  403.          {
  404.             this.selectedIndex = this.__dropdown.selectedIndex;
  405.             this.displayDropdown(false);
  406.          }
  407.       }
  408.       else if(!this._editable || e.code == 38 || e.code == 40 || e.code == 33 || e.code == 34)
  409.       {
  410.          this.selectedIndex = 0 + this.selectedIndex;
  411.          this.bInKeyDown = true;
  412.          var _loc3_ = this.dropdown;
  413.          _loc3_.keyDown(e);
  414.          this.bInKeyDown = false;
  415.          this.selectedIndex = this.__dropdown.selectedIndex;
  416.       }
  417.    }
  418.    function invalidateStyle(styleProp)
  419.    {
  420.       this.__dropdown.invalidateStyle(styleProp);
  421.       super.invalidateStyle(styleProp);
  422.    }
  423.    function changeTextStyleInChildren(styleProp)
  424.    {
  425.       if(this.dropdown.stylecache != undefined)
  426.       {
  427.          delete this.dropdown.stylecache[styleProp];
  428.          delete this.dropdown.stylecache.tf;
  429.       }
  430.       this.__dropdown.changeTextStyleInChildren(styleProp);
  431.       super.changeTextStyleInChildren(styleProp);
  432.    }
  433.    function changeColorStyleInChildren(sheetName, styleProp, newValue)
  434.    {
  435.       if(this.dropdown.stylecache != undefined)
  436.       {
  437.          delete this.dropdown.stylecache[styleProp];
  438.          delete this.dropdown.stylecache.tf;
  439.       }
  440.       this.__dropdown.changeColorStyleInChildren(sheetName,styleProp,newValue);
  441.       super.changeColorStyleInChildren(sheetName,styleProp,newValue);
  442.    }
  443.    function notifyStyleChangeInChildren(sheetName, styleProp, newValue)
  444.    {
  445.       if(this.dropdown.stylecache != undefined)
  446.       {
  447.          delete this.dropdown.stylecache[styleProp];
  448.          delete this.dropdown.stylecache.tf;
  449.       }
  450.       this.__dropdown.notifyStyleChangeInChildren(sheetName,styleProp,newValue);
  451.       super.notifyStyleChangeInChildren(sheetName,styleProp,newValue);
  452.    }
  453.    function onUnload()
  454.    {
  455.       this.__dropdown.removeMovieClip();
  456.    }
  457.    function _resizeHandler()
  458.    {
  459.       var _loc2_ = this.owner;
  460.       _loc2_.mask._width = this.width;
  461.       _loc2_.mask._height = this.height;
  462.    }
  463.    function _changeHandler(obj)
  464.    {
  465.       var _loc2_ = this.owner;
  466.       var _loc3_ = _loc2_.selectedIndex;
  467.       obj.target = _loc2_;
  468.       if(this == this.owner.text_mc)
  469.       {
  470.          _loc2_.selectedIndex = undefined;
  471.          _loc2_.dispatchChangeEvent(obj,-1,-2);
  472.       }
  473.       else
  474.       {
  475.          _loc2_.selectedIndex = this.selectedIndex;
  476.          if(!_loc2_._showingDropdown)
  477.          {
  478.             _loc2_.dispatchChangeEvent(obj,_loc3_,_loc2_.selectedIndex);
  479.          }
  480.          else if(!_loc2_.bInKeyDown)
  481.          {
  482.             _loc2_.displayDropdown(false);
  483.          }
  484.       }
  485.    }
  486.    function _scrollHandler(obj)
  487.    {
  488.       var _loc2_ = this.owner;
  489.       obj.target = _loc2_;
  490.       _loc2_.dispatchEvent(obj);
  491.    }
  492.    function _itemRollOverHandler(obj)
  493.    {
  494.       var _loc2_ = this.owner;
  495.       obj.target = _loc2_;
  496.       _loc2_.dispatchEvent(obj);
  497.    }
  498.    function _itemRollOutHandler(obj)
  499.    {
  500.       var _loc2_ = this.owner;
  501.       obj.target = _loc2_;
  502.       _loc2_.dispatchEvent(obj);
  503.    }
  504.    function modelChanged(eventObj)
  505.    {
  506.       super.modelChanged(eventObj);
  507.       if(0 == this.__dataProvider.length)
  508.       {
  509.          this.text_mc.setText("");
  510.          delete this.selected;
  511.       }
  512.       else if(this.__dataProvider.length == eventObj.lastItem - eventObj.firstItem + 1 && eventObj.eventName == "addItems")
  513.       {
  514.          this.selectedIndex = 0;
  515.       }
  516.    }
  517.    function dispatchChangeEvent(obj, prevValue, newValue)
  518.    {
  519.       var _loc2_ = undefined;
  520.       if(prevValue != newValue)
  521.       {
  522.          if(obj != undefined && obj.type == "change")
  523.          {
  524.             _loc2_ = obj;
  525.          }
  526.          else
  527.          {
  528.             _loc2_ = {type:"change"};
  529.          }
  530.          this.dispatchEvent(_loc2_);
  531.       }
  532.    }
  533. }
  534.