开发者

as3 mouseEnabled still a problem for me

A couple years in now, there's still something about mouseEnabled I'm not getting. I have a Sprite (for example here "Sky", that contains many objects, one of them is a Cloud, which I do not want to receive Mouse Events. I overlay this Sky on some other display objects. I want the cloud to be visible, but not to block mouse events. If you see a tree through the clouds you should be able to click on the tree.

In the Sky class:

mouseEnabled = false;
cloud.mouseEnabled = false;
cloud.mouseChildren = false;

Even with this conf开发者_如何学Pythoniguration, when the cloud is over the tree I can't click on the tree because the cloud blocks it. Why???


Even though Sky has mouseEnabled/mouseChildren set to false... it's still an object, it still takes up space, and therefore still acts as a hit area for any PARENT containers that don't have mouseEnabled/mouseChildren set to false.

Therefore, I suspect your Sky object is not in the same parent container as your Tree object. Your Sky object probably has its own parent container object, which is the culprit intercepting the events.

To elaborate: Any object that contains ANYTHING will have a hit area and will intercept mouse clicks, even though all the individual things it contains (shapes, child objects, etc.) may have mouseEnabled/mouseChildren set to false.

So even though your Sky object has mouseEnabled set to false, your Sky (and it's children) still take up space, and therefore still give Sky's parent container a hit area to intercept mouse events.

Your solution, therefore, is to make sure all the parent containers of Sky have thier mouseEnabled property set to false, at least up to (but not including) the first common ancestor container of the Tree and Sky objects.

Also, by setting mouseEnabled=false and leaving mouseChildren=true, you can have a container where only select children with mouseEnabled=true receive click events :)


You say there's "many objects" in there? More than likely something else is blocking it. I recommend adding a listener to the stage and then you can see which object is receiving clicks:

import flash.utils.getQualifiedClassName;
stage.addEventListener(MouseEvent.CLICK, onClick);
private function onClick(event:MouseEvent):void
{
    trace(event.target.name, getQualifiedClassName(event.target));
}

Post more code and we can probably help more.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜