导航

 Flexs.cn

Flash、AS2 、AS3、Flex、FMS、RED5、AIR 、游戏制作教程聚合

« flash游戏中控制角色惯性移动动态改变影片的注册点,MC嵌套MC »

一个全能flash滚动条,响应任意鼠标事件

http://log.7thpark.com/post/158.html
功能:可以响应鼠标拖动,鼠标划过、点击上下键,鼠标滚轮
关键词: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._y<=top) {
    scrollBar._y = top;
  }
  // end if                                    
};
Mouse.addListener(mouseListener);
//up and down btn event
scrollBar.onEnterFrame = function() {
  if (this.d && this._y<this._bottom) {
    this._y += this.s;
  }
  //end if  
  if (this.u && this._y>this._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;
  scrollBar.s = nSpeedLow;
  down = true;
};
scrollDown.onRollOut = function() {
  scrollBar.d = false;
  scrollBar.s = 0;
  down = false;
};
scrollDown.onReleaseOutside = function() {
  scrollBar.d = false;
  scrollBar.s = 0;
  down = false;
};
//up
scrollUp.onRollOver = function() {
  scrollBar.u = true;
  scrollBar.s = nSpeedLow;
  down = true;
};
scrollUp.onPress = function() {
  scrollBar.u = true;
  scrollBar.s = nSpeedHigh;
  down = true;
};
scrollUp.onRelease = function() {
  scrollBar.u = true;
  scrollBar.s = nSpeedLow;
  down = true;
};
scrollUp.onRollOut = function() {
  scrollBar.u = false;
  scrollBar.s = 0;
  down = false;
};
scrollUp.onReleaseOutside = function() {
  scrollBar.u = false;
  scrollBar.s = 0;
  down = false;
};

源文件下载

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。


Powered By MaxSugar

Copyright 2005-2007 Flexs.cn Some Rights Reserved.

Search

最近发表