[AS3]as3压缩位图BitmapData.encode用法源代码示例(5)
Box.as: packagecom.vini123.utils { importcom.vini123.tool.Button; importflash.display.Bitmap; importflash.display.Sprite; importflash.events.MouseEvent; publicclassBoxextendsSprite { privatevar_w:Num
Box.as:
- package com.vini123.utils
- {
- import com.vini123.tool.Button;
- import flash.display.Bitmap;
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- public class Box extends Sprite
- {
- private var _w:Number;
- private var _h:Number;
- private var _deleBtn:Button;
- private var _index:int;
- private var bottom:Sprite;
- private var box:Sprite;
- private var gap1:int = 4;
- private var gap2:int = 1;
- private var _bitmap:Bitmap;
- public function Box(w:Number = 250,h:Number = 180)
- {
- _w = w;
- _h = h;
- bottom = new Sprite();
- addChild(bottom);
- box = new Sprite();
- addChild(box);
- draw();
- _deleBtn = new Button("删除图片");
- addChild(_deleBtn);
- _deleBtn.x = _w - 2 * gap1 - _deleBtn.width -10;
- _deleBtn.y = _h - 2 * gap1 - _deleBtn.height -10;
- _deleBtn.buttonMode = true;
- _deleBtn.name = "deleBtn";
- _deleBtn.visible = false;
- this.addEventListener(MouseEvent.ROLL_OVER,overHandler);
- this.addEventListener(MouseEvent.ROLL_OUT,outHandler);
- }
- public function dispose():void
- {
- this.removeEventListener(MouseEvent.ROLL_OVER,overHandler);
- this.removeEventListener(MouseEvent.ROLL_OUT,outHandler);
- bottom.graphics.clear();
- box.graphics.clear();
- _deleBtn.dispose();
- _bitmap.bitmapData.dispose();
- if(this.parent)
- {
- this.parent.removeChild(this);
- }
- }
- public function get deleBtn():Button
- {
- return _deleBtn;
- }
- public function get index():int
- {
- return _index;
- }
- public function set index(value:int):void
- {
- _index = value;
- }
- private function overHandler(e:MouseEvent):void
- {
- _deleBtn.visible = true;
- }
- private function outHandler(e:MouseEvent):void
- {
- _deleBtn.visible = false;
- }
- public function get bitmap():Bitmap
- {
- return _bitmap;
- }
- public function set bitmap(value:Bitmap):void
- {
- if(_bitmap)
- {
- return;
- }
- _bitmap = value;
- var _tempW:Number = _bitmap.width;
- var _tempH:Number = _bitmap.height;
- if((_tempW/_tempH) > (_w - gap1*2 - gap2 *2)/(_h - gap1 *2 - gap2*2))
- {
- _bitmap.width =(_w - gap1*2 - gap2 *2);
- _bitmap.height = _tempH * (_w - gap1*2 - gap2 *2)/_tempW;
- }
- else
- {
- _bitmap.width = _tempW * (_h - gap1*2 - gap2 *2)/_tempH;
- _bitmap.height = _h - gap1*2 - gap2 *2;
- }
- _bitmap.x = bottom.width * 0.5 - _bitmap.width * 0.5;
- _bitmap.y = bottom.height * 0.5 - _bitmap.height * 0.5;
- addChildAt(_bitmap,this.numChildren -1);
- }
- private function draw():void
- {
- bottom.graphics.beginFill(0x00ff00,0.0);
- bottom.graphics.drawRect(0,0,_w,_h);
- bottom.graphics.endFill();
- box.graphics.lineStyle(1.2,0xADD0FC);
- box.graphics.beginFill(0xADD0FC,1);
- box.graphics.drawRoundRect(0,0,_w - gap1 *2,_h - gap1 *2,5,5);
- box.graphics.endFill();
- box.x= bottom.width * 0.5 - box.width * 0.5 ;
- box.y = bottom.height * 0.5 - box.height * 0.5;
- }
- }
- }
热门文章推荐
- [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示例
请稍候...