home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2009 May / MAC_easy_05_2009.iso / Video-Tutorial / start.swf / scripts / %3Cdefault package%3E / FScrollBarSymbol.as < prev    next >
Encoding:
Text File  |  2009-03-18  |  12.6 KB  |  400 lines

  1. FScrollBarClass = function()
  2. {
  3.    if(this._height == 4)
  4.    {
  5.       return undefined;
  6.    }
  7.    this.init();
  8.    this.minPos = this.maxPos = this.pageSize = this.largeScroll = 0;
  9.    this.smallScroll = 1;
  10.    this.width = !this.horizontal ? this._height : this._width;
  11.    this._xscale = this._yscale = 100;
  12.    this.setScrollPosition(0);
  13.    this.tabEnabled = false;
  14.    if(this._targetInstanceName.length > 0)
  15.    {
  16.       this.setScrollTarget(this._parent[this._targetInstanceName]);
  17.    }
  18.    this.tabChildren = false;
  19.    this.setSize(this.width);
  20. };
  21. FScrollBarClass.prototype = new FUIComponentClass();
  22. FScrollBarClass.prototype.setHorizontal = function(flag)
  23. {
  24.    if(this.horizontal && !flag)
  25.    {
  26.       this._xscale = 100;
  27.       this._rotation = 0;
  28.    }
  29.    else if(flag && !this.horizontal)
  30.    {
  31.       this._xscale = -100;
  32.       this._rotation = -90;
  33.    }
  34.    this.horizontal = flag;
  35. };
  36. FScrollBarClass.prototype.setScrollProperties = function(pSize, mnPos, mxPos)
  37. {
  38.    if(!this.enable)
  39.    {
  40.       return undefined;
  41.    }
  42.    this.pageSize = pSize;
  43.    this.minPos = Math.max(mnPos,0);
  44.    this.maxPos = Math.max(mxPos,0);
  45.    this.scrollPosition = Math.max(this.minPos,this.scrollPosition);
  46.    this.scrollPosition = Math.min(this.maxPos,this.scrollPosition);
  47.    if(this.maxPos - this.minPos <= 0)
  48.    {
  49.       this.scrollThumb_mc.removeMovieClip();
  50.       this.upArrow_mc.gotoAndStop(3);
  51.       this.downArrow_mc.gotoAndStop(3);
  52.       this.downArrow_mc.onPress = this.downArrow_mc.onRelease = this.downArrow_mc.onDragOut = null;
  53.       this.upArrow_mc.onPress = this.upArrow_mc.onRelease = this.upArrow_mc.onDragOut = null;
  54.       this.scrollTrack_mc.onPress = this.scrollTrack_mc.onRelease = null;
  55.       this.scrollTrack_mc.onDragOut = this.scrollTrack_mc.onRollOut = null;
  56.       this.scrollTrack_mc.useHandCursor = false;
  57.    }
  58.    else
  59.    {
  60.       var _loc2_ = this.getScrollPosition();
  61.       this.upArrow_mc.gotoAndStop(1);
  62.       this.downArrow_mc.gotoAndStop(1);
  63.       this.upArrow_mc.onPress = this.upArrow_mc.onDragOver = this.startUpScroller;
  64.       this.upArrow_mc.onRelease = this.upArrow_mc.onDragOut = this.stopScrolling;
  65.       this.downArrow_mc.onPress = this.downArrow_mc.onDragOver = this.startDownScroller;
  66.       this.downArrow_mc.onRelease = this.downArrow_mc.onDragOut = this.stopScrolling;
  67.       this.scrollTrack_mc.onPress = this.scrollTrack_mc.onDragOver = this.startTrackScroller;
  68.       this.scrollTrack_mc.onRelease = this.stopScrolling;
  69.       this.scrollTrack_mc.onDragOut = this.stopScrolling;
  70.       this.scrollTrack_mc.onRollOut = this.stopScrolling;
  71.       this.scrollTrack_mc.useHandCursor = false;
  72.       this.attachMovie("ScrollThumb","scrollThumb_mc",3);
  73.       this.scrollThumb_mc._x = 0;
  74.       this.scrollThumb_mc._y = this.upArrow_mc._height;
  75.       this.scrollThumb_mc.onRollOver = function()
  76.       {
  77.          this.mc_sliderTop.over_mc._alpha = 100;
  78.       };
  79.       this.scrollThumb_mc.onRollOut = function()
  80.       {
  81.          this.mc_sliderTop.over_mc.onEnterFrame = function()
  82.          {
  83.             if(this._alpha > 10)
  84.             {
  85.                this._alpha -= 10;
  86.             }
  87.             else
  88.             {
  89.                delete this.onEnterFrame;
  90.                this._alpha = 0;
  91.             }
  92.          };
  93.       };
  94.       this.scrollThumb_mc.onPress = this.startDragThumb;
  95.       this.scrollThumb_mc.controller = this;
  96.       this.scrollThumb_mc.onRelease = this.stopDragThumb;
  97.       this.scrollThumb_mc.onReleaseOutside = this.stopDragThumb2;
  98.       this.scrollThumb_mc.useHandCursor = true;
  99.       this.thumbHeight = this.pageSize / (this.maxPos - this.minPos + this.pageSize) * this.trackSize;
  100.       this.thumbMid_mc = this.scrollThumb_mc.mc_sliderMid;
  101.       this.thumbTop_mc = this.scrollThumb_mc.mc_sliderTop;
  102.       this.thumbBot_mc = this.scrollThumb_mc.mc_sliderBot;
  103.       this.thumbHeight = 75;
  104.       this.midHeight = this.thumbHeight - this.thumbTop_mc._height - this.thumbBot_mc._height;
  105.       this.thumbMid_mc._yScale = this.midHeight * 100 / this.thumbMid_mc._height;
  106.       this.thumbMid_mc._y = this.thumbTop_mc._height;
  107.       this.thumbBot_mc._y = this.thumbTop_mc._height + this.midHeight;
  108.       this.scrollTop = this.scrollThumb_mc._y;
  109.       this.trackHeight = this.trackSize - this.thumbHeight;
  110.       this.scrollBot = this.trackHeight + this.scrollTop;
  111.       _loc2_ = Math.min(_loc2_,this.maxPos);
  112.       this.setScrollPosition(Math.max(_loc2_,this.minPos));
  113.    }
  114. };
  115. FScrollBarClass.prototype.getScrollPosition = function()
  116. {
  117.    return this.scrollPosition;
  118. };
  119. FScrollBarClass.prototype.setScrollPosition = function(pos)
  120. {
  121.    this.scrollPosition = pos;
  122.    if(this.scrollThumb_mc != undefined)
  123.    {
  124.       pos = Math.min(pos,this.maxPos);
  125.       pos = Math.max(pos,this.minPos);
  126.    }
  127.    this.scrollThumb_mc._y = Math.floor((pos - this.minPos) * this.trackHeight / (this.maxPos - this.minPos) + this.scrollTop);
  128.    this.executeCallBack();
  129. };
  130. FScrollBarClass.prototype.setLargeScroll = function(lScroll)
  131. {
  132.    this.largeScroll = lScroll;
  133. };
  134. FScrollBarClass.prototype.setSmallScroll = function(sScroll)
  135. {
  136.    this.smallScroll = sScroll;
  137. };
  138. FScrollBarClass.prototype.setEnabled = function(enabledFlag)
  139. {
  140.    var _loc3_ = this.enable;
  141.    if(enabledFlag && !_loc3_)
  142.    {
  143.       this.enable = enabledFlag;
  144.       if(this.textField != undefined)
  145.       {
  146.          this.setScrollTarget(this.textField);
  147.       }
  148.       else
  149.       {
  150.          this.setScrollProperties(this.pageSize,this.cachedMinPos,this.cachedMaxPos);
  151.          this.setScrollPosition(this.cachedPos);
  152.       }
  153.       this.clickFilter = undefined;
  154.    }
  155.    else if(!enabledFlag && _loc3_)
  156.    {
  157.       this.textField.removeListener(this);
  158.       this.cachedPos = this.getScrollPosition();
  159.       this.cachedMinPos = this.minPos;
  160.       this.cachedMaxPos = this.maxPos;
  161.       if(this.clickFilter == undefined)
  162.       {
  163.          this.setScrollProperties(this.pageSize,0,0);
  164.       }
  165.       else
  166.       {
  167.          this.clickFilter = true;
  168.       }
  169.       this.enable = enabledFlag;
  170.    }
  171. };
  172. FScrollBarClass.prototype.setSize = function(hgt)
  173. {
  174.    if(this._height == 1)
  175.    {
  176.       return undefined;
  177.    }
  178.    this.width = hgt;
  179.    this.scrollTrack_mc._yscale = 100;
  180.    this.scrollTrack_mc._yscale = 100 * this.width / this.scrollTrack_mc._height;
  181.    if(this.upArrow_mc == undefined)
  182.    {
  183.       this.attachMovie("UpArrow","upArrow_mc",1);
  184.       this.attachMovie("DownArrow","downArrow_mc",2);
  185.       this.downArrow_mc.controller = this.upArrow_mc.controller = this;
  186.       this.upArrow_mc.useHandCursor = this.downArrow_mc.useHandCursor = false;
  187.       this.upArrow_mc._x = this.upArrow_mc._y = 0;
  188.       this.downArrow_mc._x = 0;
  189.    }
  190.    this.scrollTrack_mc.controller = this;
  191.    this.downArrow_mc._y = this.width - this.downArrow_mc._height;
  192.    this.trackSize = this.width - 2 * this.downArrow_mc._height;
  193.    if(this.textField != undefined)
  194.    {
  195.       this.onTextChanged();
  196.    }
  197.    else
  198.    {
  199.       this.setScrollProperties(this.pageSize,this.minPos,this.maxPos);
  200.    }
  201. };
  202. FScrollBarClass.prototype.scrollIt = function(inc, mode)
  203. {
  204.    var _loc3_ = this.smallScroll;
  205.    if(inc != "one")
  206.    {
  207.       _loc3_ = this.largeScroll != 0 ? this.largeScroll : this.pageSize;
  208.    }
  209.    var _loc2_ = this.getScrollPosition() + mode * _loc3_;
  210.    if(_loc2_ > this.maxPos)
  211.    {
  212.       _loc2_ = this.maxPos;
  213.    }
  214.    else if(_loc2_ < this.minPos)
  215.    {
  216.       _loc2_ = this.minPos;
  217.    }
  218.    this.setScrollPosition(_loc2_);
  219. };
  220. FScrollBarClass.prototype.startDragThumb = function()
  221. {
  222.    this.lastY = this._ymouse;
  223.    this.onMouseMove = this.controller.dragThumb;
  224. };
  225. FScrollBarClass.prototype.dragThumb = function()
  226. {
  227.    this.scrollMove = this._ymouse - this.lastY;
  228.    this.scrollMove += this._y;
  229.    if(this.scrollMove < this.controller.scrollTop)
  230.    {
  231.       this.scrollMove = this.controller.scrollTop;
  232.    }
  233.    else if(this.scrollMove > this.controller.scrollBot)
  234.    {
  235.       this.scrollMove = this.controller.scrollBot;
  236.    }
  237.    this._y = this.scrollMove;
  238.    var _loc2_ = this.controller;
  239.    _loc2_.scrollPosition = Math.round((_loc2_.maxPos - _loc2_.minPos) * (this._y - _loc2_.scrollTop) / _loc2_.trackHeight) + _loc2_.minPos;
  240.    this.controller.isScrolling = true;
  241.    updateAfterEvent();
  242.    this.controller.executeCallBack();
  243. };
  244. FScrollBarClass.prototype.stopDragThumb = function()
  245. {
  246.    this.controller.isScrolling = false;
  247.    this.onMouseMove = null;
  248. };
  249. FScrollBarClass.prototype.stopDragThumb2 = function()
  250. {
  251.    this.mc_sliderTop.over_mc.onEnterFrame = function()
  252.    {
  253.       if(this._alpha > 10)
  254.       {
  255.          this._alpha -= 10;
  256.       }
  257.       else
  258.       {
  259.          delete this.onEnterFrame;
  260.          this._alpha = 0;
  261.       }
  262.    };
  263.    this.controller.isScrolling = false;
  264.    this.onMouseMove = null;
  265. };
  266. FScrollBarClass.prototype.startTrackScroller = function()
  267. {
  268.    this.controller.trackScroller();
  269.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"page",-1);
  270. };
  271. FScrollBarClass.prototype.scrollInterval = function(inc, mode)
  272. {
  273.    clearInterval(this.scrolling);
  274.    if(inc == "page")
  275.    {
  276.       this.trackScroller();
  277.    }
  278.    else
  279.    {
  280.       this.scrollIt(inc,mode);
  281.    }
  282.    this.scrolling = setInterval(this,"scrollInterval",35,inc,mode);
  283. };
  284. FScrollBarClass.prototype.trackScroller = function()
  285. {
  286.    if(this.scrollThumb_mc._y + this.thumbHeight < this._ymouse)
  287.    {
  288.       this.scrollIt("page",1);
  289.    }
  290.    else if(this.scrollThumb_mc._y > this._ymouse)
  291.    {
  292.       this.scrollIt("page",-1);
  293.    }
  294. };
  295. FScrollBarClass.prototype.stopScrolling = function()
  296. {
  297.    this.controller.downArrow_mc.gotoAndStop(1);
  298.    this.controller.upArrow_mc.gotoAndStop(1);
  299.    clearInterval(this.controller.scrolling);
  300. };
  301. FScrollBarClass.prototype.startUpScroller = function()
  302. {
  303.    this.controller.upArrow_mc.gotoAndStop(2);
  304.    this.controller.scrollIt("one",-1);
  305.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"one",-1);
  306. };
  307. FScrollBarClass.prototype.startDownScroller = function()
  308. {
  309.    this.controller.downArrow_mc.gotoAndStop(2);
  310.    this.controller.scrollIt("one",1);
  311.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"one",1);
  312. };
  313. FScrollBarClass.prototype.setScrollTarget = function(tF)
  314. {
  315.    if(tF == undefined)
  316.    {
  317.       this.textField.removeListener(this);
  318.       delete this.textField[!this.horizontal ? "vScroller" : "hScroller"];
  319.       if(this.textField.hScroller != undefined && this.textField.vScroller != undefined)
  320.       {
  321.          this.textField.unwatch("text");
  322.          this.textField.unwatch("htmltext");
  323.       }
  324.    }
  325.    this.textField = undefined;
  326.    if(!(tF instanceof TextField))
  327.    {
  328.       return undefined;
  329.    }
  330.    this.textField = tF;
  331.    this.textField[!this.horizontal ? "vScroller" : "hScroller"] = this;
  332.    this.onTextChanged();
  333.    this.onChanged = function()
  334.    {
  335.       this.onTextChanged();
  336.    };
  337.    this.onScroller = function()
  338.    {
  339.       if(!this.isScrolling)
  340.       {
  341.          if(!this.horizontal)
  342.          {
  343.             this.setScrollPosition(this.textField.scroll);
  344.          }
  345.          else
  346.          {
  347.             this.setScrollPosition(this.textField.hscroll);
  348.          }
  349.       }
  350.    };
  351.    this.textField.addListener(this);
  352.    this.textField.watch("text",this.callback);
  353.    this.textField.watch("htmlText",this.callback);
  354. };
  355. FScrollBarClass.prototype.callback = function(prop, oldVal, newVal)
  356. {
  357.    clearInterval(this.hScroller.synchScroll);
  358.    clearInterval(this.vScroller.synchScroll);
  359.    this.hScroller.synchScroll = setInterval(this.hScroller,"onTextChanged",50);
  360.    this.vScroller.synchScroll = setInterval(this.vScroller,"onTextChanged",50);
  361.    return newVal;
  362. };
  363. FScrollBarClass.prototype.onTextChanged = function()
  364. {
  365.    if(!this.enable || this.textField == undefined)
  366.    {
  367.       return undefined;
  368.    }
  369.    clearInterval(this.synchScroll);
  370.    if(this.horizontal)
  371.    {
  372.       var _loc3_ = this.textField.hscroll;
  373.       this.setScrollProperties(this.textField._width,0,this.textField.maxhscroll);
  374.       this.setScrollPosition(Math.min(_loc3_,this.textField.maxhscroll));
  375.    }
  376.    else
  377.    {
  378.       _loc3_ = this.textField.scroll;
  379.       var _loc2_ = this.textField.bottomScroll - this.textField.scroll;
  380.       this.setScrollProperties(_loc2_,1,this.textField.maxscroll);
  381.       this.setScrollPosition(Math.min(_loc3_,this.textField.maxscroll));
  382.    }
  383. };
  384. FScrollBarClass.prototype.executeCallBack = function()
  385. {
  386.    if(this.textField == undefined)
  387.    {
  388.       super.executeCallBack();
  389.    }
  390.    else if(this.horizontal)
  391.    {
  392.       this.textField.hscroll = this.getScrollPosition();
  393.    }
  394.    else
  395.    {
  396.       this.textField.scroll = this.getScrollPosition();
  397.    }
  398. };
  399. Object.registerClass("FScrollBarSymbol",FScrollBarClass);
  400.