[AS3]as3压缩位图BitmapData.encode用法源代码示例(4)
ScrollBar.as packagecom.vini123.tool { importflash.display.Sprite; importflash.events.Event; importflash.events.MouseEvent; importflash.geom.Rectangle; publicclassScrollBarextendsSprite { privatevar_
ScrollBar.as
- package com.vini123.tool
- {
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.geom.Rectangle;
- public class ScrollBar extends Sprite
- {
- private var _upBtn:UpBtn;
- private var _downBtn:DownBtn;
- private var _lineBar:LineBar;
- private var _dragBar:DragBar;
- private var _gap:int = 2;
- private var _rec:Rectangle;
- private var _dirction:int;
- private var _scrollTarget:*;
- private var _barWidth:Number;
- private var _lineColor:int;
- private var _visible:Boolean = false;
- public function ScrollBar():void
- {
- addEventListener(Event.ADDED_TO_STAGE,addToStageHandler);
- }
- private function addToStageHandler(e:Event):void
- {
- removeEventListener(Event.ADDED_TO_STAGE,addToStageHandler);
- _upBtn = new UpBtn();
- _downBtn = new DownBtn();
- _lineBar = new LineBar();
- _dragBar = new DragBar();
- addChild(_upBtn);
- addChild(_downBtn);
- addChild(_lineBar);
- addChild(_dragBar);
- _dragBar.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
- _dragBar.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
- stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
- stage.addEventListener(MouseEvent.MOUSE_WHEEL,mouseWheelHandler);
- _downBtn.addEventListener(MouseEvent.CLICK,clickHandler);
- _upBtn.addEventListener(MouseEvent.CLICK,clickHandler);
- }
- private function mouseWheelHandler(e:MouseEvent):void
- {
- var _distance:Number = e.delta * 3;
- _dragBar.y += _distance;
- updateDragBarPosition();
- }
- private function clickHandler(e:MouseEvent):void
- {
- var _distance:Number;
- _distance = _lineBar.height * 0.2;
- switch (e.target)
- {
- case _downBtn :
- _dragBar.y -= _distance;
- break;
- case _upBtn :
- _dragBar.y += _distance;
- break;
- }
- updateDragBarPosition();
- }
- private function updateDragBarPosition():void
- {
- if (_dragBar.y <= _lineBar.y)
- {
- _dragBar.y = _lineBar.y;
- }
- else if (_dragBar.y >= (_lineBar.y + _lineBar.height - _dragBar.height))
- {
- _dragBar.y = (_lineBar.y + _lineBar.height - _dragBar.height);
- }
- enterHandler();
- }
- private function mouseDownHandler(e:MouseEvent):void
- {
- _dragBar.startDrag(false,_rec);
- useHandler();
- }
- private function mouseUpHandler(e:MouseEvent):void
- {
- _dragBar.stopDrag();
- noHandler();
- }
- private function updateBar():void
- {
- _upBtn.y = 0;
- _lineBar.y = _upBtn.y + _upBtn.height + _gap;
- _downBtn.y = _lineBar.y + _lineBar.height + _gap;
- _dragBar.x = 1;
- _dragBar.y = _lineBar.y;
- _rec = new Rectangle(_dragBar.x,_lineBar.y,0,(_lineBar.height - _dragBar.height));
- }
- /**
- * 设置拖动条的属性
- * @param _length 拖动条的总长度(竖向就是总高度,横向的就是总宽度)
- * @param _width 拖动条的宽度 (指的是上下两个按钮的宽度和高度)
- * @param _lineColor 拖动条的线条颜色
- * @param _fillColor 拖动条的填充颜色
- * @param _triangleColor 上下两个按钮里边三角形的填充颜色
- * @param _dirction 表示拖动条的方向,值为0的时候是竖向,为1的时候是横向
- * @param _visible 表示当被拖动对象小于或等于拖动条的长度时,是否显示拖动条。
- *
- */
- public function setSize(_length:Number,_width:Number,_lineColor:int,_fillColor:int,_triangleColor:int,_dirction:int,_visible:Boolean = false):void
- {
- this._dirction = _dirction;
- _upBtn.beginDraw(_width,_lineColor,_fillColor,_triangleColor);
- _downBtn.beginDraw(_width,_lineColor,_fillColor,_triangleColor);
- _dragBar.beginDraw(_width,(_length - _upBtn.height - _downBtn.height -_gap *2)*0.5,_lineColor);
- _lineBar.beginDraw(_width,(_length - _upBtn.height - _downBtn.height -_gap *2),_lineColor,_fillColor);
- this._barWidth = _width;
- this._lineColor = _lineColor;
- this._visible = _visible;
- updateBar();
- }
- /**
- *设置被拖动的对象
- * @param value
- *
- */
- public function set scrollTarget(value:*):void
- {
- _scrollTarget = value;
- var _h1:Number = this.height > _scrollTarget.height ? _lineBar.height :(this.height / _scrollTarget.height) *_lineBar.height;
- _h1_h1 = _h1 < 30 ? 30:_h1;
- _dragBar.beginDraw(_barWidth,_h1,_lineColor);
- _rec = new Rectangle(_dragBar.x,_lineBar.y,0,(_lineBar.height - _dragBar.height));
- enterHandler();
- }
- private function enterHandler(e:Event = null):void
- {
- if (_lineBar.height == _dragBar.height)
- {
- if (! _visible)
- {
- this.visible = false;
- }
- _scrollTarget.y = this.y;
- }
- else
- {
- this.visible = true;
- _scrollTarget.y = this.y + (_dragBar.y - _lineBar.y) * (this.height - _scrollTarget.height)/(_lineBar.height - _dragBar.height);
- }
- }
- private function useHandler():void
- {
- addEventListener(Event.ENTER_FRAME,enterHandler);
- }
- private function noHandler():void
- {
- removeEventListener(Event.ENTER_FRAME,enterHandler);
- }
- }
- }
- import flash.display.Shape;
- import flash.display.Sprite;
- class UpBtn extends Sprite
- {
- private var _rect:Shape;
- private var _triangle:Shape;
- public function UpBtn():void
- {
- _rect = new Shape();
- _triangle = new Shape();
- addChild(_rect);
- addChild(_triangle);
- }
- public function beginDraw(_h:Number,_lineColor:int,_fillColor:int,_triangleColor:int):void
- {
- _rect.graphics.clear();
- _rect.graphics.lineStyle(1,_lineColor);
- _rect.graphics.beginFill(_fillColor,1);
- _rect.graphics.drawRect(0,0,_h,_h);
- _rect.graphics.endFill();
- _triangle.graphics.clear();
- _triangle.graphics.lineStyle(1,_triangleColor);
- _triangle.graphics.beginFill(_triangleColor,1);
- _triangle.graphics.moveTo(_h/3,0);
- _triangle.graphics.lineTo(2*_h/3,_h/2.5);
- _triangle.graphics.lineTo(0,_h/2.5);
- _triangle.graphics.lineTo(_h/3,0);
- _triangle.x = _rect.width * 0.5 - _triangle.width * 0.5;
- _triangle.y = _rect.height * 0.5 - _triangle.height * 0.5;
- }
- }
- class DownBtn extends Sprite
- {
- private var _rect:Shape;
- private var _triangle:Shape;
- public function DownBtn():void
- {
- _rect = new Shape();
- _triangle = new Shape();
- addChild(_rect);
- addChild(_triangle);
- }
- public function beginDraw(_h:int,_lineColor:int,_fillColor:int,_triangleColor:int):void
- {
- _rect.graphics.clear();
- _rect.graphics.lineStyle(1,_lineColor);
- _rect.graphics.beginFill(_fillColor,1);
- _rect.graphics.drawRect(0,0,_h,_h);
- _rect.graphics.endFill();
- _triangle.graphics.clear();
- _triangle.graphics.lineStyle(1,_triangleColor);
- _triangle.graphics.beginFill(_triangleColor,1);
- _triangle.graphics.moveTo(0,0);
- _triangle.graphics.lineTo(2*_h/3,0);
- _triangle.graphics.lineTo(_h/3,_h/2.5);
- _triangle.graphics.lineTo(0,0);
- _triangle.x = _rect.width * 0.5 - _triangle.width * 0.5;
- _triangle.y = _rect.height * 0.5 - _triangle.height * 0.5;
- }
- }
- class LineBar extends Sprite
- {
- private var _rect:Shape;
- public function LineBar():void
- {
- _rect = new Shape();
- addChild(_rect);
- }
- public function beginDraw(_w:int,_h:int,_lineColor:int,_fillColor:int):void
- {
- _rect.graphics.clear();
- _rect.graphics.lineStyle(1,_lineColor);
- _rect.graphics.beginFill(_fillColor,1);
- _rect.graphics.drawRect(0,0,_w,_h);
- _rect.graphics.endFill();
- }
- }
- class DragBar extends Sprite
- {
- private var _rect:Shape;
- public function DragBar():void
- {
- _rect = new Shape();
- addChild(_rect);
- beginDraw(15,100,0xFFF8E9);
- }
- public function beginDraw(_w:int,_h:int,_fillColor:int):void
- {
- _rect.graphics.clear();
- _rect.graphics.beginFill(_fillColor,1);
- _rect.graphics.drawRect(0,0,(_w-1),_h);
- _rect.graphics.endFill();
- }
- }
热门文章推荐
- [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示例
请稍候...