home *** CD-ROM | disk | FTP | other *** search
/ Design Spectrum Color Visions / Design Spectrum Color Visions.iso / Data1.cab / PORTER_main.swf / scripts / %3Cdefault package%3E / FComboBoxSymbol.as < prev    next >
Encoding:
Text File  |  2003-11-26  |  13.6 KB  |  484 lines

  1. function FComboBoxClass()
  2. {
  3.    _global._popUpLevel = _global._popUpLevel != undefined ? _global._popUpLevel + 1 : 20000;
  4.    this.superHolder = _root.createEmptyMovieClip("superHolder" + _popUpLevel,_popUpLevel);
  5.    var testContainer = this.superHolder.createEmptyMovieClip("testCont",20000);
  6.    var testBox = testContainer.attachMovie("FBoundingBoxSymbol","boundingBox_mc",0);
  7.    if(testBox._name == undefined)
  8.    {
  9.       this.superHolder.removeMovieClip();
  10.       this.superHolder = this._parent.createEmptyMovieClip("superHolder" + _popUpLevel,_popUpLevel);
  11.    }
  12.    else
  13.    {
  14.       testContainer.removeMovieClip();
  15.    }
  16.    if(this.rowCount == undefined)
  17.    {
  18.       this.rowCount = 8;
  19.       this.editable = false;
  20.    }
  21.    this.itemSymbol = "FComboBoxItemSymbol";
  22.    this.init();
  23.    this.permaScrollBar = false;
  24.    this.proxyBox_mc.gotoAndStop(1);
  25.    this.width = this._width;
  26.    this.height = this.proxyBox_mc._height * this._yscale / 100;
  27.    var i = 0;
  28.    while(i < this.labels.length)
  29.    {
  30.       this.addItem(this.labels[i],this.data[i]);
  31.       i++;
  32.    }
  33.    this.lastSelected = 0;
  34.    this.selectItem(0);
  35.    this._xscale = this._yscale = 100;
  36.    this.opened = false;
  37.    this.setSize(this.width);
  38.    this.highlightTop(false);
  39.    if(this.changeHandler.length > 0)
  40.    {
  41.       this.setChangeHandler(this.changeHandler);
  42.    }
  43.    this.onUnload = function()
  44.    {
  45.       this.superHolder.removeMovieClip();
  46.    };
  47.    this.setSelectedIndex(0,false);
  48.    this.value = "";
  49.    this.focusEnabled = true;
  50.    this.changeFlag = false;
  51. }
  52. FComboBoxClass.prototype = new FScrollSelectListClass();
  53. Object.registerClass("FComboBoxSymbol",FComboBoxClass);
  54. FComboBoxClass.prototype.modelChanged = function(eventObj)
  55. {
  56.    super.modelChanged(eventObj);
  57.    var event = eventObj.event;
  58.    if(event == "addRows" || event == "deleteRows")
  59.    {
  60.       var diff = eventObj.lastRow - eventObj.firstRow + 1;
  61.       var mode = event != "addRows" ? -1 : 1;
  62.       var len = this.getLength();
  63.       var lenBefore = len - mode * diff;
  64.       if(this.rowCount > lenBefore || this.rowCount > len)
  65.       {
  66.          this.invalidate("setSize");
  67.       }
  68.       if(this.getSelectedIndex() == undefined)
  69.       {
  70.          this.setSelectedIndex(0,false);
  71.       }
  72.    }
  73.    else if(event == "updateAll")
  74.    {
  75.       this.invalidate("setSize");
  76.    }
  77. };
  78. FComboBoxClass.prototype.removeAll = function()
  79. {
  80.    if(!this.enable)
  81.    {
  82.       return undefined;
  83.    }
  84.    super.removeAll();
  85.    if(this.editable)
  86.    {
  87.       this.value = "";
  88.    }
  89.    this.invalidate("setSize");
  90. };
  91. FComboBoxClass.prototype.setSize = function(w)
  92. {
  93.    if(w == undefined || typeof w != "number" || w <= 0 || !this.enable)
  94.    {
  95.       return undefined;
  96.    }
  97.    this.proxyBox_mc._width = w;
  98.    this.container_mc.removeMovieClip();
  99.    this.measureItmHgt();
  100.    this.container_mc = this.superHolder.createEmptyMovieClip("container",3);
  101.    this.container_mc.tabChildren = false;
  102.    this.setPopUpLocation(this.container_mc);
  103.    this.container_mc.attachMovie("FBoundingBoxSymbol","boundingBox_mc",0);
  104.    this.boundingBox_mc = this.container_mc.boundingBox_mc;
  105.    this.boundingBox_mc.component = this;
  106.    this.registerSkinElement(this.boundingBox_mc.boundingBox,"background");
  107.    this.proxyBox_mc._height = this.itmHgt;
  108.    this.numDisplayed = Math.min(this.rowCount,this.getLength());
  109.    if(this.numDisplayed < 3)
  110.    {
  111.       this.numDisplayed = Math.min(3,this.getLength());
  112.    }
  113.    this.height = this.numDisplayed * (this.itmHgt - 2) + 2;
  114.    super.setSize(w,this.height);
  115.    this.attachMovie("DownArrow","downArrow",10);
  116.    this.downArrow._y = 0;
  117.    this.downArrow._width = this.itmHgt;
  118.    this.downArrow._height = this.itmHgt;
  119.    this.downArrow._x = this.proxyBox_mc._width - this.downArrow._width;
  120.    this.setEditable(this.editable);
  121.    this.container_mc._visible = this.opened;
  122.    this.highlightTop(false);
  123.    this.fader = this.superHolder.attachMovie("FBoundingBoxSymbol","faderX",4);
  124.    this.registerSkinElement(this.fader.boundingBox,"background");
  125.    this.fader._width = this.width;
  126.    this.fader._height = this.height;
  127.    this.fader._visible = false;
  128. };
  129. FComboBoxClass.prototype.setDataProvider = function(dp)
  130. {
  131.    super.setDataProvider(dp);
  132.    this.invalidate("setSize");
  133.    this.setSelectedIndex(0);
  134. };
  135. FComboBoxClass.prototype.getValue = function()
  136. {
  137.    if(this.editable)
  138.    {
  139.       return this.fLabel_mc.getLabel();
  140.    }
  141.    return super.getValue();
  142. };
  143. FComboBoxClass.prototype.getRowCount = function()
  144. {
  145.    return this.rowCount;
  146. };
  147. FComboBoxClass.prototype.setRowCount = function(count)
  148. {
  149.    this.rowCount = this.getLength() <= count ? count : Math.max(count,3);
  150.    this.setSize(this.width);
  151.    var len = this.getLength();
  152.    if(len - this.getScrollPosition() < this.rowCount)
  153.    {
  154.       this.setScrollPosition(len - Math.min(this.rowCount,len));
  155.       this.invalidate("updateControl");
  156.    }
  157. };
  158. FComboBoxClass.prototype.setEditable = function(editableFlag)
  159. {
  160.    if(!this.enable)
  161.    {
  162.       return undefined;
  163.    }
  164.    this.editable = editableFlag;
  165.    if(!this.editable)
  166.    {
  167.       this.onPress = this.pressHandler;
  168.       this.useHandCursor = false;
  169.       this.trackAsMenu = true;
  170.       this.attachMovie("FComboBoxItemSymbol","fLabel_mc",5,{controller:this,itemNum:-1});
  171.       this.fLabel_mc.onRollOver = undefined;
  172.       this.fLabel_mc.setSize(this.width - this.itmHgt + 1,this.itmHgt);
  173.       this.topLabel = this.getSelectedItem();
  174.       this.fLabel_mc.drawItem(this.topLabel,false);
  175.       this.highlightTop(false);
  176.    }
  177.    else
  178.    {
  179.       this.attachMovie("FLabelSymbol","fLabel_mc",5);
  180.       this.fLabel_txt = this.fLabel_mc.labelField;
  181.       this.fLabel_txt.type = "input";
  182.       this.fLabel_txt._x = 4;
  183.       this.fLabel_txt.onSetFocus = this.onLabelFocus;
  184.       this.fLabel_mc.setSize(this.width - this.itmHgt - 3);
  185.       delete this.onPress;
  186.       this.fLabel_txt.onKillFocus = function()
  187.       {
  188.          this._parent._parent.myOnKillFocus();
  189.       };
  190.       this.fLabel_mc.setLabel(this.value);
  191.       this.fLabel_txt.onChanged = function()
  192.       {
  193.          this._parent._parent.findInputText();
  194.       };
  195.       this.downArrow.onPress = this.buttonPressHandler;
  196.       this.downArrow.useHandCursor = false;
  197.       this.downArrow.trackAsMenu = true;
  198.    }
  199. };
  200. FComboBoxClass.prototype.setEnabled = function(enabledFlag)
  201. {
  202.    enabledFlag = !(enabledFlag == undefined || typeof enabledFlag != "boolean") ? enabledFlag : true;
  203.    super.setEnabled(enabledFlag);
  204.    this.registerSkinElement(this.boundingBox_mc.boundingBox,"background");
  205.    this.proxyBox_mc.gotoAndStop(!this.enable ? "disabled" : "enabled");
  206.    this.downArrow.gotoAndStop(!this.enable ? 3 : 1);
  207.    if(this.editable)
  208.    {
  209.       this.fLabel_txt.type = !enabledFlag ? "dynamic" : "input";
  210.       this.fLabel_txt.selectable = enabledFlag;
  211.    }
  212.    else if(enabledFlag)
  213.    {
  214.       this.fLabel_mc.drawItem(this.topLabel,false);
  215.       this.setSelectedIndex(this.getSelectedIndex(),false);
  216.    }
  217.    this.fLabel_mc.setEnabled(this.enable);
  218.    this.fLabel_txt.onSetFocus = !enabledFlag ? undefined : this.onLabelFocus;
  219. };
  220. FComboBoxClass.prototype.setSelectedIndex = function(index, flag)
  221. {
  222.    super.setSelectedIndex(index,flag);
  223.    if(!this.editable)
  224.    {
  225.       this.topLabel = this.getSelectedItem();
  226.       this.fLabel_mc.drawItem(this.topLabel,false);
  227.    }
  228.    else
  229.    {
  230.       this.value = flag == undefined ? this.getSelectedItem().label : "";
  231.       this.fLabel_mc.setLabel(this.value);
  232.    }
  233.    this.invalidate("updateControl");
  234. };
  235. FComboBoxClass.prototype.setValue = function(value)
  236. {
  237.    if(this.editable)
  238.    {
  239.       this.fLabel_mc.setLabel(value);
  240.       this.value = value;
  241.    }
  242. };
  243. FComboBoxClass.prototype.pressHandler = function()
  244. {
  245.    _root.hideTooltip();
  246.    this.focusRect.removeMovieClip();
  247.    if(this.enable)
  248.    {
  249.       if(!this.opened)
  250.       {
  251.          this.onMouseUp = this.releaseHandler;
  252.       }
  253.       else
  254.       {
  255.          this.onMouseUp = undefined;
  256.       }
  257.       this.changeFlag = false;
  258.       if(!this.focused)
  259.       {
  260.          this.pressFocus();
  261.          this.clickFilter = !this.editable ? true : false;
  262.       }
  263.       if(!this.clickFilter)
  264.       {
  265.          this.openOrClose(!this.opened);
  266.       }
  267.       else
  268.       {
  269.          this.clickFilter = false;
  270.       }
  271.    }
  272. };
  273. FComboBoxClass.prototype.clickHandler = function(itmNum)
  274. {
  275.    if(!this.focused)
  276.    {
  277.       if(this.editable)
  278.       {
  279.          this.fLabel_txt.onKillFocus = undefined;
  280.       }
  281.       this.pressFocus();
  282.    }
  283.    super.clickHandler(itmNum);
  284.    this.selectionHandler(itmNum);
  285.    this.onMouseUp = this.releaseHandler;
  286. };
  287. FComboBoxClass.prototype.highlightTop = function(flag)
  288. {
  289.    if(!this.editable)
  290.    {
  291.       this.fLabel_mc.drawItem(this.topLabel,flag);
  292.    }
  293. };
  294. FComboBoxClass.prototype.myOnSetFocus = function()
  295. {
  296.    super.myOnSetFocus();
  297.    this.fLabel_mc.highlight_mc.gotoAndStop("enabled");
  298.    this.highlightTop(true);
  299. };
  300. FComboBoxClass.prototype.drawFocusRect = function()
  301. {
  302.    this.drawRect(-2,-2,this.width + 4,this._height + 4);
  303. };
  304. FComboBoxClass.prototype.myOnKillFocus = function()
  305. {
  306.    super.myOnKillFocus();
  307.    delete this.fLabel_txt.onKeyDown;
  308.    this.openOrClose(false);
  309.    this.highlightTop(false);
  310. };
  311. FComboBoxClass.prototype.setPopUpLocation = function(mcRef)
  312. {
  313.    mcRef._x = this._x;
  314.    var point = {x:this._x,y:this._y + this.proxyBox_mc._height};
  315.    this._parent.localToGlobal(point);
  316.    mcRef._parent.globalToLocal(point);
  317.    mcRef._x = point.x;
  318.    mcRef._y = point.y;
  319.    if(this.height + mcRef._y >= Stage.height)
  320.    {
  321.       this.upward = true;
  322.       mcRef._y = point.y - this.height - this.proxyBox_mc._height;
  323.    }
  324.    else
  325.    {
  326.       this.upward = false;
  327.    }
  328. };
  329. FComboBoxClass.prototype.openOrClose = function(flag)
  330. {
  331.    if(this.getLength() == 0)
  332.    {
  333.       return undefined;
  334.    }
  335.    this.setPopUpLocation(this.container_mc);
  336.    if(this.lastSelected != -1 && (this.lastSelected < this.topDisplayed || this.lastSelected > this.topDisplayed + this.numDisplayed))
  337.    {
  338.       super.moveSelBy(this.lastSelected - this.getSelectedIndex());
  339.    }
  340.    !flag ? this.downArrow.gotoAndStop(1) : this.downArrow.gotoAndStop(2);
  341.    if(flag == this.opened)
  342.    {
  343.       return undefined;
  344.    }
  345.    this.highlightTop(!flag);
  346.    this.fadeRate = this.styleTable.popUpFade.value;
  347.    if(!flag || this.fadeRate == undefined || this.fadeRate == 0)
  348.    {
  349.       this.opened = this.container_mc._visible = flag;
  350.       return undefined;
  351.    }
  352.    this.setPopUpLocation(this.fader);
  353.    this.time = 0;
  354.    this.const = 85 / Math.sqrt(this.fadeRate);
  355.    this.fader._alpha = 85;
  356.    this.container_mc._visible = this.fader._visible = true;
  357.    this.onEnterFrame = function()
  358.    {
  359.       this.fader._alpha = 100 - (this.const * Math.sqrt(++this.time) + 15);
  360.       if(this.time >= this.fadeRate)
  361.       {
  362.          this.fader._visible = false;
  363.          delete this.onEnterFrame;
  364.          this.opened = true;
  365.       }
  366.    };
  367. };
  368. FComboBoxClass.prototype.fireChange = function()
  369. {
  370.    this.lastSelected = this.getSelectedIndex();
  371.    if(!this.editable)
  372.    {
  373.       this.topLabel = this.getSelectedItem();
  374.       this.fLabel_mc.drawItem(this.topLabel,true);
  375.    }
  376.    else
  377.    {
  378.       this.value = this.getSelectedItem().label;
  379.       this.fLabel_mc.setLabel(this.value);
  380.    }
  381.    this.executeCallback();
  382. };
  383. FComboBoxClass.prototype.releaseHandler = function()
  384. {
  385.    var onCombo = this.boundingBox_mc.hitTest(_root._xmouse,_root._ymouse);
  386.    if(this.changeFlag)
  387.    {
  388.       if(onCombo)
  389.       {
  390.          this.fireChange();
  391.       }
  392.       this.openOrClose(!this.opened);
  393.    }
  394.    else if(onCombo)
  395.    {
  396.       this.openOrClose(false);
  397.    }
  398.    else
  399.    {
  400.       this.onMouseDown = function()
  401.       {
  402.          if(!this.boundingBox_mc.hitTest(_root._xmouse,_root._ymouse) && !this.hitTest(_root._xmouse,_root._ymouse))
  403.          {
  404.             this.onMouseDown = undefined;
  405.             this.openOrClose(false);
  406.          }
  407.       };
  408.    }
  409.    this.changeFlag = false;
  410.    this.onMouseUp = undefined;
  411.    clearInterval(this.dragScrolling);
  412.    this.dragScrolling = undefined;
  413. };
  414. FComboBoxClass.prototype.moveSelBy = function(itemNum)
  415. {
  416.    if(itemNum != 0)
  417.    {
  418.       super.moveSelBy(itemNum);
  419.       if(this.editable)
  420.       {
  421.          this.setValue(this.getSelectedItem().label);
  422.       }
  423.       if(!this.opened)
  424.       {
  425.          if(this.changeFlag && !this.isSelected(this.lastSelected))
  426.          {
  427.             this.fireChange();
  428.          }
  429.       }
  430.    }
  431. };
  432. FComboBoxClass.prototype.myOnKeyDown = function()
  433. {
  434.    if(!this.focused)
  435.    {
  436.       return undefined;
  437.    }
  438.    if(this.editable && Key.isDown(13))
  439.    {
  440.       this.setValue(this.fLabel_mc.getLabel());
  441.       this.executeCallback();
  442.       this.openOrClose(false);
  443.    }
  444.    else if((Key.isDown(13) || Key.isDown(32) && !this.editable) && this.opened)
  445.    {
  446.       if(this.getSelectedIndex() != this.lastSelected)
  447.       {
  448.          this.fireChange();
  449.       }
  450.       this.openOrClose(false);
  451.       this.fLabel_txt.hscroll = 0;
  452.    }
  453.    super.myOnKeyDown();
  454. };
  455. FComboBoxClass.prototype.findInputText = function()
  456. {
  457.    if(!this.editable)
  458.    {
  459.       super.findInputText();
  460.    }
  461. };
  462. FComboBoxClass.prototype.onLabelFocus = function()
  463. {
  464.    this._parent._parent.tabFocused = false;
  465.    this._parent._parent.focused = true;
  466.    this.onKeyDown = function()
  467.    {
  468.       this._parent._parent.myOnKeyDown();
  469.    };
  470.    Key.addListener(this);
  471. };
  472. FComboBoxClass.prototype.buttonPressHandler = function()
  473. {
  474.    this._parent.pressHandler();
  475. };
  476. FComboBoxClass.prototype.onRollOver = function()
  477. {
  478.    _root.showTooltipByName(this.myTooltip);
  479. };
  480. FComboBoxClass.prototype.onRollOut = function()
  481. {
  482.    _root.hideTooltip();
  483. };
  484.