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

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

时间:2013-11-04 09:02cnblogs.com
Box.as: packagecom.vini123.utils { importcom.vini123.tool.Button; importflash.display.Bitmap; importflash.display.Sprite; importflash.events.MouseEvent; publicclassBoxextendsSprite { privatevar_w:Num

Box.as:

  1. package com.vini123.utils 
  2.     import com.vini123.tool.Button; 
  3.      
  4.     import flash.display.Bitmap; 
  5.     import flash.display.Sprite; 
  6.     import flash.events.MouseEvent; 
  7.      
  8.     public class Box extends Sprite 
  9.     { 
  10.         private var _w:Number; 
  11.         private var _h:Number; 
  12.         private var _deleBtn:Button; 
  13.         private var _index:int; 
  14.          
  15.         private var bottom:Sprite; 
  16.         private var box:Sprite; 
  17.         private var gap1:int = 4
  18.         private var gap2:int = 1
  19.         private var _bitmap:Bitmap; 
  20.  
  21.          
  22.         public function Box(w:Number = 250,h:Number = 180
  23.         { 
  24.             _w = w; 
  25.             _h = h; 
  26.              
  27.             bottom = new Sprite(); 
  28.             addChild(bottom); 
  29.              
  30.             box = new Sprite(); 
  31.             addChild(box); 
  32.              
  33.             draw(); 
  34.              
  35.             _deleBtn =  new Button("删除图片"); 
  36.             addChild(_deleBtn); 
  37.              
  38.             _deleBtn.x = _w - 2 * gap1 - _deleBtn.width -10; 
  39.             _deleBtn.y = _h - 2 * gap1 - _deleBtn.height -10; 
  40.             _deleBtn.buttonMode = true
  41.             _deleBtn.name = "deleBtn"
  42.             _deleBtn.visible = false
  43.              
  44.             this.addEventListener(MouseEvent.ROLL_OVER,overHandler); 
  45.             this.addEventListener(MouseEvent.ROLL_OUT,outHandler); 
  46.         } 
  47.          
  48.         public function dispose():void 
  49.         { 
  50.             this.removeEventListener(MouseEvent.ROLL_OVER,overHandler); 
  51.             this.removeEventListener(MouseEvent.ROLL_OUT,outHandler); 
  52.             bottom.graphics.clear(); 
  53.             box.graphics.clear(); 
  54.             _deleBtn.dispose(); 
  55.             _bitmap.bitmapData.dispose(); 
  56.             if(this.parent) 
  57.             { 
  58.                 this.parent.removeChild(this); 
  59.             } 
  60.         } 
  61.          
  62.         public function get deleBtn():Button 
  63.         { 
  64.             return _deleBtn; 
  65.         } 
  66.          
  67.         public function get index():int 
  68.         { 
  69.             return _index; 
  70.         } 
  71.  
  72.         public function set index(value:int):void 
  73.         { 
  74.             _index = value
  75.         } 
  76.  
  77.         private function overHandler(e:MouseEvent):void 
  78.         { 
  79.             _deleBtn.visible = true
  80.         } 
  81.          
  82.         private function outHandler(e:MouseEvent):void 
  83.         { 
  84.             _deleBtn.visible = false
  85.         } 
  86.          
  87.         public function get bitmap():Bitmap 
  88.         { 
  89.             return _bitmap; 
  90.         } 
  91.  
  92.         public function set bitmap(value:Bitmap):void 
  93.         { 
  94.             if(_bitmap) 
  95.             { 
  96.                 return; 
  97.             } 
  98.              
  99.             _bitmap = value
  100.              
  101.             var _tempW:Number = _bitmap.width; 
  102.             var _tempH:Number = _bitmap.height; 
  103.              
  104.             if((_tempW/_tempH) > (_w - gap1*2 - gap2 *2)/(_h - gap1 *2 - gap2*2)) 
  105.             { 
  106.                 _bitmap.width =(_w - gap1*2 - gap2 *2); 
  107.                 _bitmap.height = _tempH * (_w - gap1*2 - gap2 *2)/_tempW; 
  108.             } 
  109.             else 
  110.             { 
  111.                 _bitmap.width = _tempW * (_h - gap1*2 - gap2 *2)/_tempH; 
  112.                 _bitmap.height = _h - gap1*2 - gap2 *2; 
  113.             } 
  114.             _bitmap.x = bottom.width * 0.5 - _bitmap.width * 0.5; 
  115.             _bitmap.y = bottom.height * 0.5 - _bitmap.height * 0.5; 
  116.             addChildAt(_bitmap,this.numChildren -1); 
  117.         } 
  118.  
  119.         private function draw():void 
  120.         { 
  121.             bottom.graphics.beginFill(0x00ff00,0.0); 
  122.             bottom.graphics.drawRect(0,0,_w,_h); 
  123.             bottom.graphics.endFill(); 
  124.              
  125.             box.graphics.lineStyle(1.2,0xADD0FC); 
  126.             box.graphics.beginFill(0xADD0FC,1); 
  127.             box.graphics.drawRoundRect(0,0,_w - gap1 *2,_h - gap1 *2,5,5); 
  128.             box.graphics.endFill(); 
  129.             box.xbottom.width * 0.5 - box.width * 0.5 ; 
  130.             box.y = bottom.height * 0.5 - box.height * 0.5; 
  131.         } 
  132.     } 

 

热门文章推荐

请稍候...

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

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