从影响的MouseEvent击中格prevent某些子(仁)MouseEvent、prevent

2023-09-08 14:26:37 作者:无妻徒刑

我有我使用一个按钮一个影片剪辑。在这个影片剪辑是一个很大的阴影,显示按钮时,鼠标悬停。我的问题是,这种阴影影响的鼠标悬停并为鼠标悬停和的mouseout事件引起了更大的捕获面积比我想要的。

I've got a movieclip that I'm using as a button. Within this movieclip is a large shadow that shows when the button is moused over. My problem is that this shadow is effecting the mouseovers and causing a much larger "catch" area for the mouseOver and mouseOut events than I want.

我已经试过禁用对那个孩子鼠标事件和将mouseEnabled和mouseChildren我尽可能多的组合,能想到的。

I've tried disabling mouse events on that child and as many combinations of mouseEnabled and mouseChildren I can think of.

是否有可能影响鼠标悬停性能的它的父,或简单地定义一个定制的击中格的影片剪辑使用prevent某些元素?

Is it possible to prevent certain elements effecting the mouseover properties of it's parent, or simply defining a custom hitbox for a movieclip to use?

推荐答案

您可以使用 hitArea 属性,但它实际上也可以控制使用将mouseEnabled mouseChildren ,所以你是在正确的轨道:

You can either use the hitArea property, but it's actually also possible to control using mouseEnabled and mouseChildren, so you were on the right track:

假设你有一个影片剪辑名为buttonMC包含两个名为clickableMC和shadowMC分别影片剪辑实例

Let's say you have a movie clip called "buttonMC" that contains two movie clip instances called "clickableMC" and "shadowMC" respectively.

通过设置mouseChildren和将mouseEnabled既为false shadowMC,你不能监听鼠标事件在该实例上直接。然而,点击shadowMC仍然会触发点击buttonMC。为prevent说的mouseEnabled设置为false buttonMC。需要注意的是mouseChildren仍然应该如此buttonMC。

By setting mouseChildren and mouseEnabled both to false on shadowMC, you can't listen to mouse events on that instance directly. However, clicking on shadowMC will still trigger click on buttonMC. To prevent that set mouseEnabled to false on buttonMC. Note that mouseChildren should still be true for buttonMC.

这听起来奇怪,一个按钮的mouseEnabled设置为false,而且还有它可以点击,但想到将mouseEnabled作为一个标志,确定显示对象的图形的内容应该点击。而当shadowMC的mouseChildren和mouseEnabled设置为false,该影片剪辑的行为就好像它是图形(形状)就事件的关注。

It might sound strange to set mouseEnabled to false on a button and still have it be clickable, but think of mouseEnabled as a flag determining if the display objects's "graphics" content should be clickable. And when shadowMC's mouseChildren and mouseEnabled is set to false that movie clip will behave as if it were graphics (Shapes) as far as events are concerned.