·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[AS3]as3压缩位图BitmapData.encode用法源代码示例(4)

时间:2013-11-04 09:02cnblogs.com
ScrollBar.as packagecom.vini123.tool { importflash.display.Sprite; importflash.events.Event; importflash.events.MouseEvent; importflash.geom.Rectangle; publicclassScrollBarextendsSprite { privatevar_

ScrollBar.as  

  1. package com.vini123.tool 
  2.     import flash.display.Sprite; 
  3.     import flash.events.Event; 
  4.     import flash.events.MouseEvent; 
  5.     import flash.geom.Rectangle; 
  6.  
  7.     public class ScrollBar extends Sprite 
  8.     { 
  9.         private var _upBtn:UpBtn; 
  10.         private var _downBtn:DownBtn; 
  11.         private var _lineBar:LineBar; 
  12.         private var _dragBar:DragBar; 
  13.         private var _gap:int = 2
  14.         private var _rec:Rectangle; 
  15.  
  16.         private var _dirction:int; 
  17.         private var _scrollTarget:*; 
  18.         private var _barWidth:Number; 
  19.         private var _lineColor:int; 
  20.         private var _visible:Boolean = false
  21.  
  22.         public function ScrollBar():void 
  23.         { 
  24.             addEventListener(Event.ADDED_TO_STAGE,addToStageHandler); 
  25.         } 
  26.  
  27.         private function addToStageHandler(e:Event):void 
  28.         { 
  29.             removeEventListener(Event.ADDED_TO_STAGE,addToStageHandler); 
  30.             _upBtn = new UpBtn(); 
  31.             _downBtn = new DownBtn(); 
  32.             _lineBar = new LineBar(); 
  33.             _dragBar = new DragBar(); 
  34.             addChild(_upBtn); 
  35.             addChild(_downBtn); 
  36.             addChild(_lineBar); 
  37.             addChild(_dragBar); 
  38.             _dragBar.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler); 
  39.             _dragBar.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler); 
  40.             stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); 
  41.             stage.addEventListener(MouseEvent.MOUSE_WHEEL,mouseWheelHandler); 
  42.  
  43.             _downBtn.addEventListener(MouseEvent.CLICK,clickHandler); 
  44.             _upBtn.addEventListener(MouseEvent.CLICK,clickHandler); 
  45.         } 
  46.  
  47.         private function mouseWheelHandler(e:MouseEvent):void 
  48.         { 
  49.             var _distance:Number = e.delta * 3; 
  50.             _dragBar.y +=  _distance; 
  51.             updateDragBarPosition(); 
  52.         } 
  53.  
  54.  
  55.         private function clickHandler(e:MouseEvent):void 
  56.         { 
  57.             var _distance:Number; 
  58.             _distance = _lineBar.height * 0.2; 
  59.             switch (e.target) 
  60.             { 
  61.                 case _downBtn : 
  62.                     _dragBar.y -=  _distance
  63.                     break; 
  64.                 case _upBtn : 
  65.                     _dragBar.y +=  _distance; 
  66.                     break; 
  67.             } 
  68.             updateDragBarPosition(); 
  69.         } 
  70.  
  71.         private function updateDragBarPosition():void 
  72.         { 
  73.             if (_dragBar.y <= _lineBar.y) 
  74.             { 
  75.                 _dragBar.y = _lineBar.y; 
  76.             } 
  77.             else if (_dragBar.y >= (_lineBar.y + _lineBar.height - _dragBar.height)) 
  78.             { 
  79.                 _dragBar.y = (_lineBar.y + _lineBar.height - _dragBar.height); 
  80.             } 
  81.             enterHandler(); 
  82.         } 
  83.  
  84.         private function mouseDownHandler(e:MouseEvent):void 
  85.         { 
  86.             _dragBar.startDrag(false,_rec); 
  87.             useHandler(); 
  88.         } 
  89.  
  90.         private function mouseUpHandler(e:MouseEvent):void 
  91.         { 
  92.             _dragBar.stopDrag(); 
  93.             noHandler(); 
  94.         } 
  95.  
  96.         private function updateBar():void 
  97.         { 
  98.             _upBtn.y = 0
  99.             _lineBar.y = _upBtn.y + _upBtn.height + _gap; 
  100.             _downBtn.y = _lineBar.y + _lineBar.height + _gap; 
  101.             _dragBar.x = 1
  102.             _dragBar.y = _lineBar.y; 
  103.             _rec = new Rectangle(_dragBar.x,_lineBar.y,0,(_lineBar.height - _dragBar.height)); 
  104.         } 
  105.  
  106.         /** 
  107.          *  设置拖动条的属性  
  108.          * @param _length  拖动条的总长度(竖向就是总高度,横向的就是总宽度) 
  109.          * @param _width   拖动条的宽度 (指的是上下两个按钮的宽度和高度) 
  110.          * @param _lineColor 拖动条的线条颜色 
  111.          * @param _fillColor 拖动条的填充颜色 
  112.          * @param _triangleColor 上下两个按钮里边三角形的填充颜色 
  113.          * @param _dirction 表示拖动条的方向,值为0的时候是竖向,为1的时候是横向 
  114.          * @param _visible 表示当被拖动对象小于或等于拖动条的长度时,是否显示拖动条。 
  115.          *  
  116.          */ 
  117.         public function setSize(_length:Number,_width:Number,_lineColor:int,_fillColor:int,_triangleColor:int,_dirction:int,_visible:Boolean = false):void 
  118.         { 
  119.             this._dirction = _dirction; 
  120.             _upBtn.beginDraw(_width,_lineColor,_fillColor,_triangleColor); 
  121.             _downBtn.beginDraw(_width,_lineColor,_fillColor,_triangleColor); 
  122.             _dragBar.beginDraw(_width,(_length - _upBtn.height - _downBtn.height -_gap *2)*0.5,_lineColor); 
  123.             _lineBar.beginDraw(_width,(_length - _upBtn.height - _downBtn.height -_gap *2),_lineColor,_fillColor); 
  124.              
  125.             this._barWidth = _width
  126.             this._lineColor = _lineColor; 
  127.             this._visible = _visible; 
  128.             updateBar(); 
  129.         } 
  130.  
  131.         /** 
  132.          *设置被拖动的对象  
  133.          * @param value 
  134.          *  
  135.          */ 
  136.         public function set scrollTarget(value:*):void 
  137.         { 
  138.             _scrollTarget = value
  139.             var _h1:Number = this.height > _scrollTarget.height ? _lineBar.height :(this.height / _scrollTarget.height) *_lineBar.height; 
  140.             _h1_h1 = _h1 < 30 ? 30:_h1; 
  141.             _dragBar.beginDraw(_barWidth,_h1,_lineColor); 
  142.             _rec = new Rectangle(_dragBar.x,_lineBar.y,0,(_lineBar.height - _dragBar.height)); 
  143.             enterHandler(); 
  144.         } 
  145.  
  146.         private function enterHandler(e:Event = null):void 
  147.         { 
  148.             if (_lineBar.height == _dragBar.height) 
  149.             { 
  150.                 if (! _visible) 
  151.                 { 
  152.                     this.visible = false
  153.                 } 
  154.                 _scrollTarget.y = this.y; 
  155.             } 
  156.             else 
  157.             { 
  158.                 this.visible = true
  159.                 _scrollTarget.y = this.y + (_dragBar.y - _lineBar.y) * (this.height - _scrollTarget.height)/(_lineBar.height - _dragBar.height); 
  160.             } 
  161.         } 
  162.  
  163.         private function useHandler():void 
  164.         { 
  165.             addEventListener(Event.ENTER_FRAME,enterHandler); 
  166.         } 
  167.  
  168.         private function noHandler():void 
  169.         { 
  170.             removeEventListener(Event.ENTER_FRAME,enterHandler); 
  171.         } 
  172.     } 
  173.  
  174. import flash.display.Shape; 
  175. import flash.display.Sprite; 
  176.  
  177. class UpBtn extends Sprite 
  178.     private var _rect:Shape; 
  179.     private var _triangle:Shape; 
  180.     public function UpBtn():void 
  181.     { 
  182.         _rect = new Shape(); 
  183.         _triangle = new Shape(); 
  184.         addChild(_rect); 
  185.         addChild(_triangle); 
  186.     } 
  187.  
  188.     public function beginDraw(_h:Number,_lineColor:int,_fillColor:int,_triangleColor:int):void 
  189.     { 
  190.         _rect.graphics.clear(); 
  191.         _rect.graphics.lineStyle(1,_lineColor); 
  192.         _rect.graphics.beginFill(_fillColor,1); 
  193.         _rect.graphics.drawRect(0,0,_h,_h); 
  194.         _rect.graphics.endFill(); 
  195.  
  196.         _triangle.graphics.clear(); 
  197.         _triangle.graphics.lineStyle(1,_triangleColor); 
  198.         _triangle.graphics.beginFill(_triangleColor,1); 
  199.  
  200.         _triangle.graphics.moveTo(_h/3,0); 
  201.         _triangle.graphics.lineTo(2*_h/3,_h/2.5); 
  202.         _triangle.graphics.lineTo(0,_h/2.5); 
  203.         _triangle.graphics.lineTo(_h/3,0); 
  204.  
  205.         _triangle.x = _rect.width * 0.5 - _triangle.width * 0.5; 
  206.         _triangle.y = _rect.height * 0.5 - _triangle.height * 0.5; 
  207.     } 
  208.  
  209. class DownBtn extends Sprite 
  210.     private var _rect:Shape; 
  211.     private var _triangle:Shape; 
  212.  
  213.     public function DownBtn():void 
  214.     { 
  215.         _rect = new Shape(); 
  216.         _triangle = new Shape(); 
  217.         addChild(_rect); 
  218.         addChild(_triangle); 
  219.     } 
  220.  
  221.     public function beginDraw(_h:int,_lineColor:int,_fillColor:int,_triangleColor:int):void 
  222.     { 
  223.         _rect.graphics.clear(); 
  224.         _rect.graphics.lineStyle(1,_lineColor); 
  225.         _rect.graphics.beginFill(_fillColor,1); 
  226.         _rect.graphics.drawRect(0,0,_h,_h); 
  227.         _rect.graphics.endFill(); 
  228.  
  229.         _triangle.graphics.clear(); 
  230.         _triangle.graphics.lineStyle(1,_triangleColor); 
  231.         _triangle.graphics.beginFill(_triangleColor,1); 
  232.         _triangle.graphics.moveTo(0,0); 
  233.         _triangle.graphics.lineTo(2*_h/3,0); 
  234.         _triangle.graphics.lineTo(_h/3,_h/2.5); 
  235.         _triangle.graphics.lineTo(0,0); 
  236.  
  237.         _triangle.x = _rect.width * 0.5 - _triangle.width * 0.5; 
  238.         _triangle.y = _rect.height * 0.5 - _triangle.height * 0.5; 
  239.     } 
  240.  
  241. class LineBar extends Sprite 
  242.  
  243.     private var _rect:Shape; 
  244.     public function LineBar():void 
  245.     { 
  246.         _rect = new Shape(); 
  247.         addChild(_rect); 
  248.     } 
  249.  
  250.     public function beginDraw(_w:int,_h:int,_lineColor:int,_fillColor:int):void 
  251.     { 
  252.         _rect.graphics.clear(); 
  253.         _rect.graphics.lineStyle(1,_lineColor); 
  254.         _rect.graphics.beginFill(_fillColor,1); 
  255.         _rect.graphics.drawRect(0,0,_w,_h); 
  256.         _rect.graphics.endFill(); 
  257.     } 
  258.  
  259. class DragBar extends Sprite 
  260.     private var _rect:Shape; 
  261.     public function DragBar():void 
  262.     { 
  263.         _rect = new Shape(); 
  264.         addChild(_rect); 
  265.         beginDraw(15,100,0xFFF8E9); 
  266.     } 
  267.  
  268.     public function beginDraw(_w:int,_h:int,_fillColor:int):void 
  269.     { 
  270.         _rect.graphics.clear(); 
  271.         _rect.graphics.beginFill(_fillColor,1); 
  272.         _rect.graphics.drawRect(0,0,(_w-1),_h); 
  273.         _rect.graphics.endFill(); 
  274.     } 

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器