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

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

时间:2013-11-04 09:02cnblogs.com
Button.as packagecom.vini123.tool { importflash.display.Sprite; importflash.events.MouseEvent; importflash.text.TextField; importflash.text.TextFieldAutoSize; importflash.text.TextFormat; publicclass

Button.as

  1. package com.vini123.tool 
  2.     import flash.display.Sprite; 
  3.     import flash.events.MouseEvent; 
  4.     import flash.text.TextField; 
  5.     import flash.text.TextFieldAutoSize; 
  6.     import flash.text.TextFormat; 
  7.      
  8.     public class Button extends Sprite 
  9.     { 
  10.         private var _txtFormat:TextFormat; 
  11.         private var _txt:TextField 
  12.         private var _bottom:Sprite; 
  13.         private var _gap:int =7
  14.          
  15.         public function Button(label:String):void 
  16.         { 
  17.             _txtFormat = new TextFormat(); 
  18.             _txtFormat.size = 13
  19.             _txtFormat.color = 0xADD0FC
  20.              
  21.             _txt = new TextField(); 
  22.             _txt.text = label
  23.             _txt.autoSize = TextFieldAutoSize.LEFT; 
  24.             _txt.setTextFormat(_txtFormat); 
  25.             _txt.mouseEnabled = false
  26.             addChild(_txt); 
  27.              
  28.             _bottom = new Sprite(); 
  29.             _bottom.graphics.lineStyle(1.0,0x2D72B5); 
  30.             _bottom.graphics.beginFill(0x0099ff,1); 
  31.             _bottom.graphics.drawRoundRect(0,0,_txt.textWidth + _gap *2,_txt.textHeight + _gap,5,5); 
  32.             _bottom.graphics.endFill(); 
  33.             addChildAt(_bottom,0); 
  34.              
  35.             _txt.x = _gap
  36.             _txt.y = _gap * 0.5 -1; 
  37.              
  38.             this.addEventListener(MouseEvent.ROLL_OVER,overHandler); 
  39.             this.addEventListener(MouseEvent.ROLL_OUT,outHandler); 
  40.         } 
  41.          
  42.         private function overHandler(e:MouseEvent):void 
  43.         { 
  44.             _txt.alpha = 0.65; 
  45.         } 
  46.          
  47.         private function outHandler(e:MouseEvent):void 
  48.         { 
  49.             _txt.alpha = 1
  50.         } 
  51.          
  52.         public function dispose():void 
  53.         { 
  54.             _bottom.graphics.clear(); 
  55.             this.removeEventListener(MouseEvent.ROLL_OVER,overHandler); 
  56.             this.removeEventListener(MouseEvent.ROLL_OUT,outHandler); 
  57.             if(this.parent) 
  58.             { 
  59.                 this.parent.removeChild(this); 
  60.             } 
  61.         } 
  62.     } 

热门文章推荐

请稍候...

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

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