home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Demo / elearn / Chimie / interfata.swf / scripts / FListBoxSymbol.as < prev    next >
Text File  |  2004-05-12  |  5KB  |  161 lines

  1. function FListBoxClass()
  2. {
  3.    this.itemSymbol = "FListItemSymbol";
  4.    this.init();
  5.    this.permaScrollBar = true;
  6.    var i = 0;
  7.    while(i < this.labels.length)
  8.    {
  9.       this.addItem(this.labels[i],this.data[i]);
  10.       i++;
  11.    }
  12.    this.boundingBox_mc.gotoAndStop(1);
  13.    this.width = this._width;
  14.    this.height = this._height;
  15.    this._yscale = this._xscale = 100;
  16.    this.setSize(this.width,this.height);
  17.    if(this.changeHandler.length > 0)
  18.    {
  19.       this.setChangeHandler(this.changeHandler);
  20.    }
  21. }
  22. FListBoxClass.prototype = new FScrollSelectListClass();
  23. Object.registerClass("FListBoxSymbol",FListBoxClass);
  24. FListBoxClass.prototype.getSelectedIndices = function()
  25. {
  26.    var tmpArray = new Array();
  27.    for(var i in this.selected)
  28.    {
  29.       tmpArray.push(this.selected[i].sIndex);
  30.    }
  31.    return tmpArray.length <= 0 ? undefined : tmpArray;
  32. };
  33. FListBoxClass.prototype.getSelectedItems = function()
  34. {
  35.    var indices = this.getSelectedIndices();
  36.    var tmpArray = new Array();
  37.    var i = 0;
  38.    while(i < indices.length)
  39.    {
  40.       tmpArray.push(this.getItemAt(indices[i]));
  41.       i++;
  42.    }
  43.    return tmpArray.length <= 0 ? undefined : tmpArray;
  44. };
  45. FListBoxClass.prototype.getSelectMultiple = function()
  46. {
  47.    return this.selectMultiple;
  48. };
  49. FListBoxClass.prototype.getRowCount = function()
  50. {
  51.    return this.numDisplayed;
  52. };
  53. FListBoxClass.prototype.setSelectedIndices = function(indexArray)
  54. {
  55.    this.clearSelected();
  56.    var i = 0;
  57.    while(i < indexArray.length)
  58.    {
  59.       this.selectItem(indexArray[i],true);
  60.       i++;
  61.    }
  62.    this.updateControl();
  63. };
  64. FListBoxClass.prototype.setSelectMultiple = function(flag)
  65. {
  66.    this.selectMultiple = flag;
  67. };
  68. FListBoxClass.prototype.setRowCount = function(count)
  69. {
  70.    var hgt = count * (this.itmHgt - 2) + 2;
  71.    this.setSize(this.width,hgt);
  72. };
  73. FListBoxClass.prototype.setWidth = function(wdt)
  74. {
  75.    this.setSize(wdt,this.height);
  76. };
  77. FListBoxClass.prototype.setSize = function(w, h)
  78. {
  79.    if(!this.enable)
  80.    {
  81.       return undefined;
  82.    }
  83.    w = Math.max(w,20);
  84.    h = Math.max(h,40);
  85.    this.container_mc.removeMovieClip();
  86.    this.container_mc = this.createEmptyMovieClip("container",3);
  87.    this.measureItmHgt();
  88.    this.numDisplayed = Math.floor(h / (this.itmHgt - 2));
  89.    this.height = this.numDisplayed * (this.itmHgt - 2) + 2;
  90.    super.setSize(w,this.height);
  91. };
  92. FListBoxClass.prototype.removeItemAt = function(index)
  93. {
  94.    this.selectHolder = this.getSelectedIndices();
  95.    return super.removeItemAt(index);
  96. };
  97. FListBoxClass.prototype.selectionHandler = function(itemNum)
  98. {
  99.    if(this.clickFilter)
  100.    {
  101.       var index = this.topDisplayed + itemNum;
  102.       if(this.getItemAt(index) == undefined)
  103.       {
  104.          this.changeFlag = false;
  105.          return undefined;
  106.       }
  107.       this.changeFlag = true;
  108.       if(!this.selectMultiple && !Key.isDown(17) || !Key.isDown(16) && !Key.isDown(17))
  109.       {
  110.          this.clearSelected();
  111.          this.selectItem(index,true);
  112.          this.lastSelected = index;
  113.          this.container_mc["fListItem" + itemNum + "_mc"].drawItem(this.getItemAt(index),this.isSelected(index));
  114.       }
  115.       else if(Key.isDown(16) && this.selectMultiple)
  116.       {
  117.          if(this.lastSelected == -1)
  118.          {
  119.             this.lastSelected = index;
  120.          }
  121.          var incr = this.lastSelected >= index ? -1 : 1;
  122.          this.clearSelected();
  123.          var i = this.lastSelected;
  124.          while(i != index)
  125.          {
  126.             this.selectItem(i,true);
  127.             if(i >= this.topDisplayed && i < this.topDisplayed + this.numDisplayed)
  128.             {
  129.                this.container_mc["fListItem" + (i - this.topDisplayed) + "_mc"].drawItem(this.getItemAt(i),this.isSelected(i));
  130.             }
  131.             i += incr;
  132.          }
  133.          this.selectItem(index,true);
  134.          this.container_mc["fListItem" + (index - this.topDisplayed) + "_mc"].drawItem(this.getItemAt(index),this.isSelected(index));
  135.       }
  136.       else if(key.isDown(17))
  137.       {
  138.          var selectedFlag = this.isSelected(index);
  139.          if(!this.selectMultiple)
  140.          {
  141.             this.clearSelected();
  142.          }
  143.          if(!(!this.selectMultiple && selectedFlag))
  144.          {
  145.             this.selectItem(index,!selectedFlag);
  146.             this.container_mc["fListItem" + itemNum + "_mc"].drawItem(this.getItemAt(this.topDisplayed + itemNum),this.isSelected(this.topDisplayed + itemNum));
  147.          }
  148.          this.lastSelected = index;
  149.       }
  150.    }
  151.    else
  152.    {
  153.       this.clickFilter = true;
  154.    }
  155. };
  156. FListBoxClass.prototype.moveSelBy = function(itemNum)
  157. {
  158.    super.moveSelBy(itemNum);
  159.    this.releaseHandler();
  160. };
  161.