全能flash滾動條,響應任意鼠標事件

功能:可以響應鼠標拖動,鼠標劃過、點擊上下鍵,鼠標滾輪
關鍵詞:flash 滾動文本 偵聽器
說明:這個市參考了別人的東西我自己寫的,代碼使用很方便只要調整遮照層的位置和拖動的scrollbar的位置就可以了,對其方式是完全自動的。以下是代碼(寫在關鍵楨上,其中scrollMask遮照了滾動文本內容scrollContent,而scrollBar就是滾動條被拖動的了,scrollLine是滾動條的背景,那條線,scrollUp是滾動條向上的箭頭,scrollDown是滾動條向下的箭頭,全部爲實例名)
//  http://log.7thpark.com
//各mc縱座標自動基於scrollMask定位,頂端對齊;
//scoll的控制條部分根據scrollBar的橫座標自動居中對齊;
//不需要修改代碼
var _maskY:Number = int(scrollMask._y);
var _maskH:Number = int(scrollMask._height);
var _barH:Number = int(scrollBar._height);
var _upH:Number = int(scrollUp._height);
var _downH:Number = int(scrollDown._height);
var top:Number = _maskY+_upH;
var bottom:Number = _maskY+_maskH-_barH-_downH;
scrollBar._top = top;
scrollBar._bottom = bottom;
left = int(scrollBar._x);
scrollBar._y = _maskY+_upH;
scrollContent._y = _maskY;
scrollLine._y = _maskY;
scrollLine._height = _maskH;
scrollUp._y = _maskY;
scrollDown._y = _maskY+_maskH-_downH;
var barC:Number = int(scrollBar._x+scrollBar._width/2)+1;
scrollLine._x = int(barC-scrollLine._width/2);
scrollUp._x = int(barC-scrollUp._width/2);
scrollDown._x = int(barC-scrollDown._width/2);
var speed:Number = 6;
var nSpeedLow:Number = 1;
var nSpeedHigh:Number = 3;
dis = (scrollContent._height-_maskH+10)/(bottom-top);
contentStartY = scrollContent._y;
var down:Boolean = true;
scrollContent._y = bottom;
scrollBar.onPress = function() {
  scrollBar.startDrag(0, left, top, left, bottom);
  down = true;
};
scrollBar.onMouseUp = function() {
  scrollBar.stopDrag();
  down = true;
};
this.onEnterFrame = function() {
  if (down) {
    disMove = (scrollBar._y-top)*dis;
    scrollContent.yMove = contentStartY-disMove;
  }
  // end if                                       
  scrollContent._y = scrollContent._y+(scrollContent.yMove-scrollContent._y)/speed;
};
//mousewheel event------------------------
mouseListener = new Object();
mouseListener.onMouseWheel = function(delta) {
  down = true;
  scrollBar._y = scrollBar._y-delta*3;
  if (scrollBar._y>=bottom) {
    scrollBar._y = bottom;
} else if (scrollBar._ythis._top) {
    this._y -= this.s;
  }
  //end if  
};
//down
scrollDown.onRollOver = function() {
  scrollBar.d = true;
  scrollBar.s = nSpeedLow;
  down = true;
};
scrollDown.onPress = function() {
  scrollBar.d = true;
  scrollBar.s = nSpeedHigh;
  down = true;
};
scrollDown.onRelease = function() {
  scrollBar.d = true;
本文轉自:http://www.5uflash.com/flashjiaocheng/Flashyingyongkaifa/912.html
發佈了0 篇原創文章 · 獲贊 0 · 訪問量 1513
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章