忽略PNG透明区域的事件(AS/Flash)
来源:互联网 发布:数据录入员北京兼职 编辑:程序博客网 时间:2024/05/18 01:22
此文出现源于忽略PNG透明区域的事件(Flex)...
下面是纯as的实现..用的是Loader..帮群里的朋友写的实例
详情的思路什么的就不说了..看上面的地址
效果(左边的PNGLoader加截的png忽略透明,右边的为普通Loader):
代码:
PNGLoader.as
01.
package
net.l4cd.display
02.
{
03.
import
flash.display.BitmapData;
04.
import
flash.display.Loader;
05.
import
flash.display.Sprite;
06.
import
flash.events.Event;
07.
import
flash.events.IOErrorEvent;
08.
import
flash.events.ProgressEvent;
09.
import
flash.geom.Matrix;
10.
import
flash.net.URLRequest;
11.
import
flash.system.LoaderContext;
12.
import
flash.utils.ByteArray;
13.
14.
/**
15.
* PNGLoader,主要解决png图片透明像素处事件的问题
16.
* @author L4cd.Net
17.
*
18.
*/
19.
public
class
PNGLoader
extends
Sprite
20.
{
21.
private
var
loader:Loader =
new
Loader();
22.
private
var
hit:Sprite =
new
Sprite();
23.
public
function
PNGLoader()
24.
{
25.
addChild(loader);
26.
addChild(hit);
27.
hit.visible =
false
;
28.
hit.mouseEnabled =
false
;
29.
mouseChildren =
false
;
30.
hitArea = hit;
31.
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,complete);
32.
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,error);
33.
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progress);
34.
}
35.
private
function
complete(e:Event):
void
36.
{
37.
dispatchEvent(e);
38.
update();
39.
}
40.
private
function
error(e:IOErrorEvent):
void
41.
{
42.
dispatchEvent(e);
43.
}
44.
private
function
progress(e:ProgressEvent):
void
45.
{
46.
dispatchEvent(e);
47.
}
48.
public
function
load(request:URLRequest,context:LoaderContext=
null
):
void
49.
{
50.
loader.load(request,context);
51.
clear();
52.
}
53.
public
function
loadBytes(bytes:ByteArray,context:LoaderContext=
null
):
void
54.
{
55.
loader.loadBytes(bytes,context);
56.
clear();
57.
}
58.
public
function
unload():
void
59.
{
60.
loader.unload();
61.
clear();
62.
}
63.
public
function
close():
void
64.
{
65.
loader.close();
66.
clear();
67.
}
68.
private
function
clear():
void
69.
{
70.
hit.graphics.clear();
71.
}
72.
private
function
update():
void
73.
{
74.
if
(!loader.content)
return
;
75.
var
bit:BitmapData =
new
BitmapData(loader.width,loader.height,
true
,
0x00000000
);
76.
bit.draw(loader);
77.
//重绘图象到bit
78.
clear();
79.
hit.graphics.beginFill(
0
);
80.
for
(
var
x:
uint
=
0
;x<bit.width;x++)
81.
{
82.
for
(
var
y:
uint
=
0
;y<bit.height;y++)
83.
{
84.
if
(bit.getPixel32(x,y))hit.graphics.drawRect(x,y,
1
,
1
);
85.
}
86.
}
87.
//以graphics画出bit的无透明区域
88.
hit.graphics.endFill();
89.
}
90.
}
91.
}
PNGLoaderExample.as
01.
package
02.
{
03.
import
flash.display.Loader;
04.
import
flash.display.Sprite;
05.
import
flash.events.MouseEvent;
06.
import
flash.filters.GlowFilter;
07.
import
flash.net.URLRequest;
08.
09.
import
net.l4cd.display.PNGLoader;
10.
11.
12.
[SWF(width=
"600"
,height=
"400"
)]
13.
/**
14.
* PNGLoaderExample
15.
* @author L4cd.Net
16.
*
17.
*/
18.
public
class
PNGLoaderExample
extends
Sprite
19.
{
20.
public
function
PNGLoaderExample()
21.
{
22.
var
pl:PNGLoader =
new
PNGLoader();
23.
pl.load(
new
URLRequest(
"10020601.png"
));
24.
addChild(pl);
25.
pl.y =
20
;
26.
pl.addEventListener(MouseEvent.ROLL_OUT,o);
27.
pl.addEventListener(MouseEvent.ROLL_OVER,o);
28.
29.
var
ld:Loader =
new
Loader();
30.
ld.load(
new
URLRequest(
"10020601.png"
));
31.
addChild(ld);
32.
ld.x =
320
;
33.
ld.y =
20
;
34.
ld.addEventListener(MouseEvent.ROLL_OUT,o);
35.
ld.addEventListener(MouseEvent.ROLL_OVER,o);
36.
37.
38.
graphics.lineStyle(
1
);
39.
graphics.drawRect(
20
,
20
,
250
,
250
);
40.
41.
graphics.drawRect(
320
,
20
,
250
,
250
);
42.
}
43.
private
function
o(e:MouseEvent):
void
44.
{
45.
e.target.filters = (e.type == MouseEvent.ROLL_OVER)?[
new
GlowFilter()]:[];
46.
}
47.
}
48.
}
- 忽略PNG透明区域的事件(AS/Flash)
- AS忽略png透明区域的鼠标事件
- 忽略透明区域的事件
- 忽略图片透明区域的事件(Flex)
- 忽略图片透明区域的事件(Flex)
- flash解决png透明区域不响应鼠标事件 as3.0
- 过滤PNG透明区域的鼠标状态
- FLASH 透明区域抠图
- 窗口透明和PNG图片区域透明按钮使用方法
- 设置PNG非透明区域为mask区域
- Android ImageView包含透明区域的图片点击事件处理
- 如何拉伸有透明区域的png图片来做UIButton的背景图片
- 9.png 部分区域莫名变透明问题
- [swift] UIImage NSImage PNG透明区域填充自定义颜色实现
- png 透明的一些问题
- 显示透明的PNG图片
- .9.png的区域划分
- 透明区域不响应鼠标事件做法
- 所见即得的壁纸下载工具更新
- Oracle JDeveloper 10g Release Download
- jdeveloper 9i download
- GBUZZ的一些感想...
- 设置边缘模糊的mask效果
- 忽略PNG透明区域的事件(AS/Flash)
- 这些是源自几米的句子,让人满心感触……
- 收拾收拾` 回家过年
- 世无艰难 何来人杰——Leo的2010展望
- 邢台市火车票代售点
- 郭德纲绝句,没有一句不让你笑的
- mount
- 对存储的一些认识
- HDS USP