功能:可以响应鼠标拖动,鼠标划过、点击上下键,鼠标滚轮
关键词: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
关键词: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