[AS3]as3.0写的一个滚动条代码实例flash滚动条
[AS3]as3.0写的一个滚动条代码实例flash滚动条
[AS3]as3.0写的一个滚动条代码实例
- function scrollbar(scrollObject:Sprite, scrollDisplay:Sprite, scrollBar:Sprite, scrollBarLine:Sprite) {
- var ScrollDrag:Boolean = false;
- var scrollBarscrollBar_y:Number = scrollBar.y = scrollBar.y;
- var scrollObjectscrollObject_y:Number = scrollObject.y = scrollBar_y;
- var wheel:Boolean = false;
- scrollObject.mask = scrollDisplay;
- scrollBarLine.height = scrollDisplay.height;
- scrollBar.height = scrollBarLine.height/(scrollObject.height/scrollBarLine.height);
- scrollObject.addEventListener(MouseEvent.ROLL_OVER, function(){
- wheel = true;
- });
- scrollObject.addEventListener(MouseEvent.MOUSE_OUT, function(){
- wheel = false;
- });
- stage.addEventListener(MouseEvent.MOUSE_WHEEL, function(e:MouseEvent){
- if(wheel) {
- if(e.delta > 0) {
- scrollBar.y-= Math.abs(e.delta);
- if(scrollBar.y <= scrollBar_y) scrollBar.y = scrollBar_y;
- }else{
- scrollBar.y+= Math.abs(e.delta);
- if((scrollBar.y - scrollBar_y) >= (scrollBarLine.height - scrollBar.height)) scrollBar.y = scrollBar_y + (scrollBarLine.height - scrollBar.height);
- }
- scrollObject.y = scrollObject_y - (scrollBar.y - scrollBar_y)*(scrollObject.height/scrollBarLine.height);
- }
- })
- stage.addEventListener(Event.ENTER_FRAME, function(){
- if(ScrollDrag) {
- scrollObject.y = scrollObject_y - (scrollBar.y - scrollBar_y)*(scrollObject.height/scrollBarLine.height);
- }
- });
- scrollBar.addEventListener(MouseEvent.MOUSE_DOWN, function(){
- ScrollDrag = true;
- scrollBar.startDrag(false, new Rectangle(scrollBar.x, scrollBar_y, 0, scrollBarLine.height - scrollBar.height));
- });
- stage.addEventListener(MouseEvent.MOUSE_UP, function(){
- if(ScrollDrag) {
- ScrollDrag = false;
- scrollBar.stopDrag();
- }
- });
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...