[AS3]flash滚动条用于响应鼠标事件的示例代码
代码使用很方便只要调整遮照层的位置和拖动的scrollbar的位置就可以了,对其方式是完全自动的。以下是代码(写在关键桢上,其中 scrollMask遮照了滚动文本内容scrollContent
功能:可以响应鼠标拖动,鼠标划过、点击上下键,鼠标滚轮
关键词:flash 滚动文本 侦听器
说明:代码使用很方便只要调整遮照层的位置和拖动的scrollbar的位置就可以了,对其方式是完全自动的。以下是代码(写在关键桢上,其中 scrollMask遮照了滚动文本内容scrollContent,而scrollBar就是滚动条被拖动的了,scrollLine是滚动条的背景, 那条线,scrollUp是滚动条向上的箭头,scrollDown是滚动条向下的箭头,全部为实例名)
- //各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;
- }
- // cuplayer.com
- scrollContentscrollContent._y = scrollContent._y+(scrollContent.yMove-scrollContent._y)/speed;
- };
- //mousewheel event------------------------
- mouseListener = new Object();
- mouseListener.onMouseWheel = function(delta) {
- down = true;
- scrollBarscrollBar._y = scrollBar._y-delta*3;
- if (scrollBar._y>=bottom) {
- scrollBar._y = bottom;
- } else if (scrollBar._y<=top) {
- scrollBar._y = top;
- }
- // cuplayer.com
- };
- Mouse.addListener(mouseListener);
- //up and down btn event
- scrollBar.onEnterFrame = function() {
- if (this.d && this._y<this._bottom) {
- this._y += this.s;
- }
- // cuplayer.com
- if (this.u && this._y>this._top) {
- this._y -= this.s;
- }
- // cuplayer.com
- };
- //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 cuplayer.com
- 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;
- };
热门文章推荐
- [FMS]Adobe FMS产品(Adobe Flash Media Server)使用介绍(组图)
- [FMS]Flash Media Server之教程附示例代码
- [RTMP]国产RTMP/HLS直播服务器simple-rtmp-server
- [WOWZA]用wowza流媒体服务器发布和播放直播流(RTMP)
- [RTMP]又一款rtmp类的服务器openrtmfp流媒体服务器
- [RTMP]adobe之FMS视频直播解决方案流程介绍(组图)
- [RTMP协议]实时消息传输协议 (RTMP) 常识性介绍
- [FMS]Adobe的Flash Media Server服务器(FMS服务器)安装
请稍候...