检查的透明度透明度

2023-09-08 11:56:11 作者:單身跪族

我的swf文件(900x600),而该文件的主要部分是transparense。 所以,我想通过单击SWF文件知道无论用户点击图像transa preNT的一部分或不...

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();