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

 

热门文章推荐

请稍候...

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

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