检查透明度 [英] Check transparency

查看:42
本文介绍了检查透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 swf 文件(900x600),该文件的主要部分是透明的.所以我想通过点击 swf 文件知道用户是否点击了图像的透明部分...

I have swf file(900x600) and main part of that file is transparense. So I want by clicking in swf file know either user clicks on transaprent part of image or not...

我可以通过

event.localX
event.localY

那么如何知道被点击的部分 swf 是否透明?

So how to know in clicked part swf is transparent or not?

推荐答案

首先,请确保您的 swf 背景中有一些透明的精灵 - 否则您将不会收到事件.

First of all, be sure, that you have some transparent sprite on background of your swf - otherwise you won't receive event.

第二,不要使用纯局部坐标,它们可以包含另一个内部对象的局部坐标,而你需要它们来自根.例如,我使用了舞台的坐标

Second, do not use pure local coordinates, they can contain local coordinates of another inner object, while you need them from root. For example, I've used stage's coordinates

如果您收到鼠标事件,请将鼠标事件侦听器添加到该 swf 的根目录并写入以下内容:

If you receive mouse event, add mouse event listener to the root of that swf and write following:

        var bmd:BitmapData = new BitmapData(1, 1, true, 0);
        var pt:Point = new Point();
        var m:Matrix = new Matrix();

        m.translate(-e.stageX, -e.stageY);
        bmd.draw(this, m);
        var transparent:Boolean = !bmd.hitTest(pt, 0x00, pt);

        trace('color: '+bmd.getPixel32(0,0).toString(16));
        trace('is tranparent? ' + transparent);

        bmd.dispose();

这篇关于检查透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆