views:

687

answers:

3

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 configuration, when the cloud is over the tree I can't click on the tree because the cloud blocks it. Why???

A: 

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.

Typeoneerror
ok, forget the "many objects" part. Just one object that I want disabled, and one that I want enabled. The enabled object is very small and not affecting this. Here's what I get when I use the code you posted:instance5 flash.display::Sprite
phil
ok, so there's a sprite on there without an instance name that is receiving the click instead of cloud. does your tree have an instance name? I'd give your clips names so you can figure out which one is actually blocking.
Typeoneerror
+1  A: 

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 :)

Triynko
A: 

thankyou Triynko your explanation about keeping in mind what parent display objects are actually in context when you click saved me hours. cheers!