问题
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.
I've tried disabling mouse events on that child and as many combinations of mouseEnabled and mouseChildren I can think of.
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?
回答1:
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:
Let's say you have a movie clip called "buttonMC" that contains two movie clip instances called "clickableMC" and "shadowMC" respectively.
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.
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.
来源:https://stackoverflow.com/questions/18786210/prevent-certain-children-from-affecting-mouseevent-hitbox