home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Swf / Toolkits.swf / scripts / __Packages / com / rightactionscript / fcb / components / ScrollBar.as < prev    next >
Encoding:
Text File  |  2010-02-25  |  10.3 KB  |  333 lines

  1. class com.rightactionscript.fcb.components.ScrollBar extends com.rightactionscript.fcb.components.UIBasicComponent
  2. {
  3.    var mcBoundingBox;
  4.    var mcHolder;
  5.    var mcUpArrowTemp;
  6.    var mcDownArrowTemp;
  7.    var mcTrackTemp;
  8.    var mcThumbTemp;
  9.    var interval;
  10.    var onRelease;
  11.    var onRollOut;
  12.    var dispatchInterval;
  13.    var scrollInterval;
  14.    var mcThumb;
  15.    var _nPage;
  16.    var _nMin;
  17.    var _nMax;
  18.    var _nDragOffset;
  19.    var _nPrevScrollPosition;
  20.    var dispatchEvent;
  21.    var _tTarget;
  22.    var addEventListener;
  23.    var _sSnapTo;
  24.    var _oListener;
  25.    var target;
  26.    var parent;
  27.    var _nSize;
  28.    var _bHorizontal;
  29.    var __height;
  30.    function ScrollBar()
  31.    {
  32.       super();
  33.    }
  34.    function createChildren()
  35.    {
  36.       this.mcBoundingBox._visible = false;
  37.       this.mcBoundingBox._width = 0;
  38.       this.mcBoundingBox._height = 0;
  39.       this.createEmptyMovieClip("mcHolder",this.getNextHighestDepth());
  40.       this.mcHolder.attachMovie("ScrollBarUpArrow","mcUpArrow",this.mcHolder.getNextHighestDepth());
  41.       this.mcHolder.attachMovie("ScrollBarDownArrow","mcDownArrow",this.mcHolder.getNextHighestDepth());
  42.       this.mcHolder.attachMovie("ScrollBarTrack","mcTrack",this.mcHolder.getNextHighestDepth());
  43.       this.mcHolder.attachMovie("ScrollThumb","mcThumb",this.mcHolder.getNextHighestDepth());
  44.       this.mcUpArrowTemp._visible = false;
  45.       this.mcDownArrowTemp._visible = false;
  46.       this.mcTrackTemp._visible = false;
  47.       this.mcThumbTemp._visible = false;
  48.       this.mcHolder.mcUpArrow.onRollOver = function()
  49.       {
  50.          this.gotoAndStop("over");
  51.       };
  52.       this.mcHolder.mcUpArrow.onRollOut = function()
  53.       {
  54.          this.gotoAndStop("up");
  55.       };
  56.       this.mcHolder.mcUpArrow.onPress = function()
  57.       {
  58.          this.gotoAndStop("down");
  59.          this.interval = setInterval(this._parent._parent,"scrollThumb",50,-1,false);
  60.       };
  61.       this.mcHolder.mcUpArrow.onRelease = function()
  62.       {
  63.          this.gotoAndStop("over");
  64.          clearInterval(this.interval);
  65.       };
  66.       this.mcHolder.mcUpArrow.onReleaseOutside = function()
  67.       {
  68.          this.onRelease();
  69.          this.onRollOut();
  70.       };
  71.       this.mcHolder.mcDownArrow.onRollOver = function()
  72.       {
  73.          this.gotoAndStop("over");
  74.       };
  75.       this.mcHolder.mcDownArrow.onRollOut = function()
  76.       {
  77.          this.gotoAndStop("up");
  78.       };
  79.       this.mcHolder.mcDownArrow.onPress = function()
  80.       {
  81.          this.gotoAndStop("down");
  82.          this.interval = setInterval(this._parent._parent,"scrollThumb",50,1,false);
  83.       };
  84.       this.mcHolder.mcDownArrow.onRelease = function()
  85.       {
  86.          this.gotoAndStop("over");
  87.          clearInterval(this.interval);
  88.       };
  89.       this.mcHolder.mcDownArrow.onReleaseOutside = function()
  90.       {
  91.          this.onRelease();
  92.          this.onRollOut();
  93.       };
  94.       this.mcHolder.mcThumb.onRollOver = function()
  95.       {
  96.          for(var _loc2_ in this)
  97.          {
  98.             this[_loc2_].gotoAndStop("over");
  99.          }
  100.       };
  101.       this.mcHolder.mcThumb.onRollOut = function()
  102.       {
  103.          for(var _loc2_ in this)
  104.          {
  105.             this[_loc2_].gotoAndStop("up");
  106.          }
  107.       };
  108.       this.mcHolder.mcThumb.onPress = function()
  109.       {
  110.          for(var _loc2_ in this)
  111.          {
  112.             this[_loc2_].gotoAndStop("down");
  113.          }
  114.          this._parent._parent._nDragOffset = - this._ymouse;
  115.          this.dispatchInterval = setInterval(this._parent._parent,"dispatchScrollEvent",50);
  116.          this.scrollInterval = setInterval(this._parent._parent,"scrollThumb",50,null,true);
  117.       };
  118.       this.mcHolder.mcThumb.onRelease = this.mcThumb.onReleaseOutside = function()
  119.       {
  120.          for(var _loc2_ in this)
  121.          {
  122.             this[_loc2_].gotoAndStop("over");
  123.          }
  124.          clearInterval(this.scrollInterval);
  125.          clearInterval(this.dispatchInterval);
  126.       };
  127.       this.mcHolder.mcThumb.onReleaseOutside = function()
  128.       {
  129.          this.onRelease();
  130.          this.onRollOut();
  131.       };
  132.       this.mcHolder.mcTrack.onPress = function()
  133.       {
  134.          if(this._parent._parent._parent._bHorizontal)
  135.          {
  136.             var _loc4_ = this._parent._xmouse;
  137.             var _loc3_ = this._parent.mcThumb._x;
  138.          }
  139.          else
  140.          {
  141.             _loc4_ = this._parent._ymouse;
  142.             _loc3_ = this._parent.mcThumb._y;
  143.          }
  144.          var _loc2_ = this._parent._parent._nPage * 100 / (this._parent._parent._nMax - this._parent._parent._nMin);
  145.          if(_loc4_ < _loc3_)
  146.          {
  147.             _loc2_ = - _loc2_;
  148.          }
  149.          this._parent._parent.scrollThumb(_loc2_);
  150.       };
  151.    }
  152.    function setScrollProperties(nPage, nMin, nMax)
  153.    {
  154.       this._nPage = nPage;
  155.       this._nMin = Math.max(nMin,0);
  156.       this._nMax = Math.max(nMax,0);
  157.       this.resizeThumb();
  158.    }
  159.    function resizeThumb()
  160.    {
  161.       this.mcHolder.mcThumb.height = Math.abs(this._nPage / (this._nMax - this._nMin) * this.mcHolder.mcTrack._height);
  162.       this.mcHolder.mcThumb._y = this.mcHolder.mcUpArrow._height;
  163.       if(this.mcHolder.mcThumb.height > this.mcHolder.mcTrack._height)
  164.       {
  165.          this.mcHolder.mcThumb._visible = false;
  166.       }
  167.       else
  168.       {
  169.          this.mcHolder.mcThumb._visible = true;
  170.       }
  171.    }
  172.    function scrollThumb(nAmount, bDrag)
  173.    {
  174.       if(bDrag)
  175.       {
  176.          this.mcHolder.mcThumb._y = this.mcHolder._ymouse + this._nDragOffset;
  177.       }
  178.       else
  179.       {
  180.          this.mcHolder.mcThumb._y += nAmount;
  181.       }
  182.       if(this.mcHolder.mcThumb._y < this.mcHolder.mcUpArrow._height)
  183.       {
  184.          this.mcHolder.mcThumb._y = this.mcHolder.mcUpArrow._height;
  185.       }
  186.       else if(this.mcHolder.mcThumb._y > this.mcHolder.mcDownArrow._y - this.mcHolder.mcThumb._height)
  187.       {
  188.          this.mcHolder.mcThumb._y = this.mcHolder.mcDownArrow._y - this.mcHolder.mcThumb._height;
  189.       }
  190.       this.dispatchScrollEvent();
  191.    }
  192.    function dispatchScrollEvent()
  193.    {
  194.       if(this.mcHolder.mcThumb._y != this._nPrevScrollPosition)
  195.       {
  196.          this._nPrevScrollPosition = this.mcHolder.mcThumb._y;
  197.          this.dispatchEvent({type:"scroll",target:this});
  198.       }
  199.    }
  200.    function set scrollTarget(tTarget)
  201.    {
  202.       this._tTarget = typeof tTarget != "string" ? tTarget : this._parent[tTarget];
  203.       if(this._tTarget == "" || this._tTarget == null)
  204.       {
  205.          this._tTarget = undefined;
  206.          return;
  207.       }
  208.       if(this.addEventListener != undefined)
  209.       {
  210.          this.addTargetListener();
  211.       }
  212.       this.addToQueue({object:this,method:this.addTargetListener});
  213.       if(this._sSnapTo != undefined && this._sSnapTo != "none")
  214.       {
  215.          this.addToQueue({object:this,method:this.snapToTextField});
  216.       }
  217.    }
  218.    function get scrollTarget()
  219.    {
  220.       return this._tTarget;
  221.    }
  222.    function set snapTo(sSnapTo)
  223.    {
  224.       this._sSnapTo = sSnapTo;
  225.       if(this._tTarget != undefined)
  226.       {
  227.          if(this.addEventListener != undefined)
  228.          {
  229.             this.snapToTextField();
  230.          }
  231.          else
  232.          {
  233.             this.addToQueue({object:this,method:this.snapToTextField});
  234.          }
  235.       }
  236.    }
  237.    function snapToTextField()
  238.    {
  239.       if(this._sSnapTo == "right")
  240.       {
  241.          this._x = this._tTarget._x + this._tTarget._width - this._width;
  242.          this._y = this._tTarget._y;
  243.          this._tTarget._width -= this._width;
  244.          this.height = this._tTarget._height;
  245.          this.setScrollPropertiesToTarget();
  246.       }
  247.    }
  248.    function addTargetListener()
  249.    {
  250.       this._oListener = new Object();
  251.       this._oListener.target = this._tTarget;
  252.       this._oListener.parent = this;
  253.       this._oListener.scroll = function(oEvent)
  254.       {
  255.          this.target.scroll = this.target.maxscroll * (this.parent.scrollPosition / Math.abs(this.parent._nMax - this.parent._nMin));
  256.       };
  257.       this.addEventListener("scroll",this._oListener);
  258.       this.setScrollPropertiesToTarget();
  259.    }
  260.    function setScrollPropertiesToTarget()
  261.    {
  262.       var _loc2_ = this._tTarget.textHeight;
  263.       var _loc3_ = 0.9 * this._tTarget._height / _loc2_ * this._tTarget.maxscroll;
  264.       this.setScrollProperties(_loc3_,0,this._tTarget.maxscroll);
  265.    }
  266.    function set scrollPosition(nScrollPosition)
  267.    {
  268.       this.mcHolder.mcThumb._y = nScrollPosition * (this.mcHolder.mcTrack._height - this.mcHolder.mcThumb._height) / (this._nMax - this._nMin) + this.mcHolder.mcTrack._y;
  269.       if(this.mcHolder.mcThumb._y + this.mcHolder.mcThumb._height > this.mcHolder.mcDownArrow._y)
  270.       {
  271.          this.mcHolder.mcThumb._y = this.mcHolder.mcDownArrow._y - this.mcHolder.mcThumb._height;
  272.       }
  273.    }
  274.    function get scrollPosition()
  275.    {
  276.       return Math.round((this.mcHolder.mcThumb._y - this.mcHolder.mcTrack._y) / (this.mcHolder.mcTrack._height - this.mcHolder.mcThumb._height) * (this._nMax - this._nMin));
  277.    }
  278.    function arrange()
  279.    {
  280.       if(this._nSize == undefined)
  281.       {
  282.          return undefined;
  283.       }
  284.       super.arrange();
  285.       this._xscale = 100;
  286.       this._yscale = 100;
  287.       if(this._bHorizontal)
  288.       {
  289.          this.mcHolder._rotation = -90;
  290.       }
  291.       this.mcHolder.mcTrack._height = Math.max(this._nSize - this.mcHolder.mcUpArrow._height - this.mcHolder.mcDownArrow._height,0);
  292.       this.mcHolder.mcTrack._y = this.mcHolder.mcUpArrow._height;
  293.       this.mcHolder.mcDownArrow._y = this.mcHolder.mcTrack._y + this.mcHolder.mcTrack._height;
  294.       this.mcHolder.mcThumb._y = this.mcHolder.mcTrack._y;
  295.       this.mcHolder.mcThumb._x = 2;
  296.       if(this.mcHolder.mcThumb._height > this.mcHolder.mcTrack._height)
  297.       {
  298.          this.mcHolder.mcThumb._visible = false;
  299.       }
  300.       else
  301.       {
  302.          this.mcHolder.mcThumb._visible = true;
  303.       }
  304.    }
  305.    function size()
  306.    {
  307.       super.size();
  308.       this._nSize = this.__height;
  309.       this.arrange();
  310.    }
  311.    function set horizontal(bHorizontal)
  312.    {
  313.       this._bHorizontal = bHorizontal;
  314.       this.arrange();
  315.    }
  316.    function init()
  317.    {
  318.       super.init();
  319.       if(this._nMin == undefined)
  320.       {
  321.          this._nMin = 0;
  322.       }
  323.       if(this._nMax == undefined)
  324.       {
  325.          this._nMax = 100;
  326.       }
  327.       if(this._nPage == undefined)
  328.       {
  329.          this._nPage = 10;
  330.       }
  331.    }
  332. }
  333.