home *** CD-ROM | disk | FTP | other *** search
- class Scrollbar extends MovieClip
- {
- var scrollBarTrackTop;
- var up;
- var scrollBarTrackHeight;
- var lowestYPosForBar;
- var onMouseUp;
- var down;
- var middle;
- var bg;
- var onEnterFrame;
- var scrollButtonPressed = false;
- var scrollerMovingBar = 0;
- var scrollerMovingBarMove = 10;
- var scrollerMovingBarJump = 90;
- var scrollBarPercentage = 0;
- var scrollerDragging = false;
- var scrollerDragOffset = 0;
- var scrollBarTopOfWindow = 0;
- var scrollBarWindowShowHeight = 0;
- var scrollBarWindowScrollHeight = 0;
- var scrollerAttachedTo = null;
- function Scrollbar()
- {
- super();
- }
- function attachScrollBar(attachTo, bottomMargin)
- {
- this.scrollBarTrackTop = this.up._y + this.up._height + 2;
- this.scrollBarTrackHeight = this._height - this.scrollBarTrackTop * 2;
- this.lowestYPosForBar = 0;
- this.scrollBarTopOfWindow = attachTo._y;
- var _loc4_ = this._height;
- if(attachTo._height > _loc4_)
- {
- this.scrollerAttachedTo = attachTo;
- if(attachTo.selectClass)
- {
- attachTo.selectClass.attachedScrollBar = this;
- }
- else
- {
- attachTo.attachedScrollBar = this;
- }
- this.scrollBarWindowShowHeight = _loc4_;
- this._visible = true;
- this.onMouseUp = this.stopScroll;
- this.up.onPress = function()
- {
- this._parent.startScrollUp();
- };
- this.down.onPress = function()
- {
- this._parent.startScrollDown();
- };
- this.middle.onPress = function()
- {
- this._parent.startScrollDrag();
- };
- this.bg.onPress = function()
- {
- this._parent.scrollerBGPressed();
- };
- this.scrollBarWindowScrollHeight = attachTo._height + bottomMargin;
- this.checkScrollingWindow();
- var _loc2_ = this.scrollBarTrackHeight * (this.scrollBarWindowShowHeight / this.scrollBarWindowScrollHeight);
- if(_loc2_ > this.scrollBarTrackHeight)
- {
- _loc2_ = this.scrollBarTrackHeight;
- }
- if(_loc2_ < 10)
- {
- _loc2_ = 10;
- }
- this.middle._height = _loc2_;
- this.middle._y = this.scrollBarTrackTop;
- this.lowestYPosForBar = this.scrollBarTrackHeight - this.middle._height;
- this.moveScrollBarPosition();
- }
- else
- {
- this.removeScrollBar();
- }
- }
- function removeScrollBar(Void)
- {
- this._visible = false;
- if(this.scrollerAttachedTo)
- {
- this.scrollerAttachedTo._y = this.scrollBarTopOfWindow;
- }
- this.scrollerAttachedTo = null;
- this.onMouseUp = null;
- this.up.onPress = null;
- this.down.onPress = null;
- this.middle.onPress = null;
- this.bg.onPress = null;
- }
- function moveScroller(Void)
- {
- if(this.scrollerDragging)
- {
- var _loc2_ = this.getMouseYRelativeTo(this) - this.scrollerDragOffset;
- if(_loc2_ < 0)
- {
- _loc2_ = 0;
- }
- if(_loc2_ > this.lowestYPosForBar)
- {
- _loc2_ = this.lowestYPosForBar;
- }
- this.scrollerAttachedTo._y = this.scrollBarTopOfWindow - _loc2_ / this.lowestYPosForBar * (this.scrollBarWindowScrollHeight - this.scrollBarWindowShowHeight);
- this.checkScrollingWindow();
- this.moveScrollBarPosition();
- }
- else if(this.scrollerMovingBar != 0)
- {
- this.scrollerAttachedTo._y += this.scrollerMovingBar;
- this.checkScrollingWindow();
- this.moveScrollBarPosition();
- }
- if(!this.scrollerDragging && this.scrollerMovingBar != 0)
- {
- if(!this.scrollButtonPressed)
- {
- this.scrollerMovingBar *= 0.6;
- if(this.scrollerMovingBar > 0 && this.scrollerMovingBar < 1)
- {
- this.scrollerMovingBar = 0;
- this.onEnterFrame = null;
- }
- else if(this.scrollerMovingBar < 0 && this.scrollerMovingBar > -1)
- {
- this.scrollerMovingBar = 0;
- this.onEnterFrame = null;
- }
- }
- else
- {
- this.scrollerMovingBar *= 1.1;
- }
- }
- }
- function scrollerBGPressed(Void)
- {
- var _loc2_ = this.getMouseYRelativeTo(this) - this.middle._y;
- if(_loc2_ < 0)
- {
- this.scrollerMovingBar = this.scrollerMovingBarJump;
- }
- if(_loc2_ > this.middle._height)
- {
- this.scrollerMovingBar = - this.scrollerMovingBarJump;
- }
- this.scrollButtonPressed = true;
- this.scrollerDragging = false;
- this.onEnterFrame = this.moveScroller;
- }
- function jumpToPosition(jumpToPos)
- {
- this.scrollerAttachedTo._y = this._y + jumpToPos;
- this.checkScrollingWindow();
- this.moveScrollBarPosition();
- }
- function checkScrollingWindow(Void)
- {
- if(this.scrollerAttachedTo._y < this.scrollBarWindowShowHeight + this.scrollBarTopOfWindow - this.scrollBarWindowScrollHeight)
- {
- this.scrollerAttachedTo._y = this.scrollBarWindowShowHeight + this.scrollBarTopOfWindow - this.scrollBarWindowScrollHeight;
- if(!this.scrollerDragging)
- {
- this.stopScroll();
- }
- }
- if(this.scrollerAttachedTo._y > this.scrollBarTopOfWindow)
- {
- this.scrollerAttachedTo._y = this.scrollBarTopOfWindow;
- if(!this.scrollerDragging)
- {
- this.stopScroll();
- }
- }
- }
- function moveScrollBarPosition(Void)
- {
- if(this.scrollerAttachedTo)
- {
- this.middle._y = this.scrollBarTrackTop + Math.abs(this.scrollerAttachedTo._y - this.scrollBarTopOfWindow) / (this.scrollBarWindowScrollHeight - this.scrollBarWindowShowHeight) * this.lowestYPosForBar;
- }
- }
- function startScrollUp(Void)
- {
- this.scrollerMovingBar = this.scrollerMovingBarMove;
- this.scrollButtonPressed = true;
- this.scrollerDragging = false;
- this.onEnterFrame = this.moveScroller;
- }
- function startScrollDown(Void)
- {
- this.scrollerMovingBar = - this.scrollerMovingBarMove;
- this.scrollButtonPressed = true;
- this.scrollerDragging = false;
- this.onEnterFrame = this.moveScroller;
- }
- function startScrollDrag(Void)
- {
- this.scrollerMovingBar = 0;
- this.scrollerDragOffset = this.getMouseYRelativeTo(this) - this.middle._y + this.scrollBarTrackTop;
- this.scrollerDragging = true;
- this.scrollButtonPressed = false;
- this.onEnterFrame = this.moveScroller;
- }
- function stopScroll(Void)
- {
- this.scrollButtonPressed = false;
- this.scrollerDragging = false;
- }
- function getMouseYRelativeTo(relativeTo)
- {
- var _loc2_ = new Object();
- _loc2_.x = 0;
- _loc2_.y = _root._ymouse;
- relativeTo.globalToLocal(_loc2_);
- return _loc2_.y;
- }
- }
-