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?
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.
Related
I'm not even sure if this is a problem that can be solved through code. I have simple movie clips in an array that I'm trying to add click Event Listeners to, and I can change the buttonMode to true and add the event Listener, but only one of the movieclips actually shows the behavioral changes from the buttonMode and event Listener.
for(var d:int = 0; d < doors.length; d++)
{
doors[d].buttonMode = true;
doors[d].addEventListener(MouseEvent.CLICK, doorClick);
trace(doors[d].buttonMode);
trace(doors[d].hasEventListener(MouseEvent.CLICK));
}
all the traces return true, and I traced d and doors[d] to make sure that the problem wasn't with the array, but it isn't and only the door at index 1 works as intended. How can I find why the listeners aren't working?
Isolate your doors and loop. The code will work on its own without other elements. I've had this same problem before and it's usually because the invisible portion of another movieclip is overlaying the button objects.
If you're adding other MovieClips dynamically that may overlay the doors, locate the container movieclip of those objects and set its properties mouseEnabled and mouseChildren to false. The container and its child objects will no longer receive mouse clicks instead of your door movieclips.
The answer here clarified the issue for me:
https://stackoverflow.com/a/2686510/629407
I've a MovieClip that contains lot of children.
One of them is a big (and useless) shadow the graphic designer put there to make my life harder (and also the user's one, probably)
:)
Now I'm facing a little issue: the shadow is catching the MouseEvents attached to the main MovieClip (its parent), and this is very bad because it's very distant from the rest of the graphic. I'm now trying to avoid it.
Obviously I've already tried to set the shadow mc's properties mouseEnabled and mouseChildren to false, but it doesn't work.
I've found a previous thread (here), facing the same situation. But the solution accepted looks like it's not working for me.
What I am missing?
If mouseEnabled and mouseChildren is not working for you then use e.target.name property.
But first you will have to give a name to that shadow MovieClip (say shadowMC).
If you added it dynamically then use,
yourDynamicMC.name = "shadowMC"
If added manually on the stage then give instance name as "shadowMC",
Then, inside your code where you have MouseEvent function for parent MovieClip add the following lines
if(e.target.name != "shadowMC")
{
//Then proceed
}
Reading your question, I am assuming you already tried to set the parent MovieClip's mouseChildren to true with mouseEnabled to false and then set the children's mouseEnabled to true (except for the shadow). This solution should work in my opinion so I am guessing the event might be caught by one parent of your movieclip (you do not give much information about this).
Try to add a listener to the stage to see which object is receiving your MouseEvents:
import flash.utils.getQualifiedClassName;
stage.addEventListener(MouseEvent.CLICK, onClick);
private function onClick(event:MouseEvent):void
{
trace(event.target.name, getQualifiedClassName(event.target));
}
Try changing the hit area of your MovieClip. see the MovieClip doc here, this will override you MovieClip zone.
I have this problem, I use this image pan class: http://www.lextalkington.com/blog/2009/08/auto-pan-class-for-panning-an-image-on-mouse-movement/
but the problem is that the objects/sprites/movieclips that are in it have to be clickable, only problem is that the mouseChildren adn mouseEnabled properties can't be applied to a Rectangle object.
Anyone has an idea on how to be able to click through this so I can acces my objects in the panned item? (if that makes any sense...)
This class is using a Rectangle as the scrollRect for the image. The scrollRect only specifies the visible area of the image. It is not the thing you want to detect mouse clicks on.
Instead, you can listen for a mouse click on the image itself.
From the code you linked to, the image is a DisplayObject variable named _clip.
In the constructor for that image panning class, you can add your mouse listener:
_clip.addEventListener(MouseEvent.CLICK, onImageClick);
Then define the event handler:
private function onImageClick(event:Event):void
{
// do something
}
By the way, since _clip is a DisplayObject, it doesn't have mouseChildren or mouseEnabled properties (those are defined in subclasses of DisplayObject).
_clip.mouseEnable = false;
this should work, considering tha _clip will be clicked through
The .mouseEnabled doesn't work like it does on usual MovieClips. What's up?
Try setting selectable, mouseEnabled, mouseChildren, and for giggles mouseWheelEnabled all to false
Use
text_field.mouseEnabled = false;
text_field.mouseChildren = false;
mouseChildren means it's children don't register mouse events, they just dispatch from the parent. To completely disable it, BOTH need to be false.
Since the textfield is a child of the movie clip, the mouseChildren property is what is going to affect it, and you could just set that to false and it would still work.
I have two movie-clips,
one is small-box and another is big-box .Both are rectangular shape. Small- box has an index 0, and big-box has an index 1. Their x,y are same and big-box being big in size gets hide small-box. Now the problem is the listener attached to small-box does not fire as big-box is on the top of small-box. what would be the way to get listener fired when click on small-box area??
Set mouseEnabled = false on the clip covering your button to make clicks go trough to objects below. If your boxes have children of their own, you may also need to set mouseChildren = false.