[AS3]as3.0忽略PNG透明区域的代码示例
[AS3]as3.0忽略PNG透明区域的代码示例,as3与png,png取消透明事件
[AS3]as3.0忽略PNG透明区域的代码示例 代码:
PNGLoader.as
- package net.l4cd.display
- {
- import flash.display.BitmapData;
- import flash.display.Loader;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.events.IOErrorEvent;
- import flash.events.ProgressEvent;
- import flash.geom.Matrix;
- import flash.net.URLRequest;
- import flash.system.LoaderContext;
- import flash.utils.ByteArray;
- /**
- * PNGLoader,主要解决png图片透明像素处事件的问题
- * @author L4cd.Net
- *
- */
- public class PNGLoader extends Sprite
- {
- private var loader:Loader = new Loader();
- private var hit:Sprite = new Sprite();
- public function PNGLoader()
- {
- addChild(loader);
- addChild(hit);
- hit.visible = false;
- hit.mouseEnabled = false;
- mouseChildren = false;
- hithitArea = hit;
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE,complete);
- loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,error);
- loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progress);
- }
- private function complete(e:Event):void
- {
- dispatchEvent(e);
- update();
- }
- private function error(e:IOErrorEvent):void
- {
- dispatchEvent(e);
- }
- private function progress(e:ProgressEvent):void
- {
- dispatchEvent(e);
- }
- public function load(request:URLRequest,context:LoaderContext=null):void
- {
- loader.load(request,context);
- clear();
- }
- public function loadBytes(bytes:ByteArray,context:LoaderContext=null):void
- {
- loader.loadBytes(bytes,context);
- clear();
- }
- public function unload():void
- {
- loader.unload();
- clear();
- }
- public function close():void
- {
- loader.close();
- clear();
- }
- private function clear():void
- {
- hit.graphics.clear();
- }
- private function update():void
- {
- if(!loader.content)return;
- var bit:BitmapData = new BitmapData(loader.width,loader.height,true,0x00000000);
- bit.draw(loader);
- //重绘图象到bit
- clear();
- hit.graphics.beginFill(0);
- for(var x:uint=0;x<bit.width;x++)
- {
- for(var y:uint=0;y<bit.height;y++)
- {
- if(bit.getPixel32(x,y))hit.graphics.drawRect(x,y,1,1);
- }
- }
- //以graphics画出bit的无透明区域
- hit.graphics.endFill();
- }
- }
- }
- PNGLoaderExample.as
- view plaincopy to clipboardprint?
- package
- {
- import flash.display.Loader;
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- import flash.filters.GlowFilter;
- import flash.net.URLRequest;
- import net.l4cd.display.PNGLoader;
- [SWF(width="600",height="400")]
- /**
- * PNGLoaderExample
- * @author L4cd.Net
- *
- */
- public class PNGLoaderExample extends Sprite
- {
- public function PNGLoaderExample()
- {
- var pl:PNGLoader = new PNGLoader();
- pl.load(new URLRequest("10020601.png"));
- addChild(pl);
- pl.y = 20;
- pl.addEventListener(MouseEvent.ROLL_OUT,o);
- pl.addEventListener(MouseEvent.ROLL_OVER,o);
- var ld:Loader = new Loader();
- ld.load(new URLRequest("10020601.png"));
- addChild(ld);
- ld.x = 320;
- ld.y = 20;
- ld.addEventListener(MouseEvent.ROLL_OUT,o);
- ld.addEventListener(MouseEvent.ROLL_OVER,o);
- graphics.lineStyle(1);
- graphics.drawRect(20,20,250,250);
- graphics.drawRect(320,20,250,250);
- }
- private function o(e:MouseEvent):void
- {
- e.target.filters = (e.type == MouseEvent.ROLL_OVER)?[new GlowFilter()]:[];
- }
- }
- }
热门文章推荐
- [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示例
请稍候...