How to click through a Rectangle (like mouseChildren = true) - actionscript-3

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

Related

as3 Buttonmode not working

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

Disable mouse event for a specific child of a movieclip

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.

Prevent certain child(ren) from affecting MouseEvent hitbox

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.

AS3 addChild() drawing on top of my movieClip on CLICK

So basically my issue is when I click on my movieClip I want it to spawn this animation I did over the protonCore. Essentially to show that when you click the protonCore you generate 1 proton. However the problem with this when spamming your CLICK, is that when it adds this child on every click, it draws on top of the movieClip and prevents hit detection while the addedChild "fuseSpark" is added to the stage. Is there a way to make it so when I add this child it doesn't affect the hitBox of the clickable movieClip?
function protonGenerator(e:MouseEvent):void
{
var fuseSpark:MovieClip = new MC_FX_fuse;
stage.addChild(fuseSpark);
fuseSpark.x = stage_protonCore.x;
fuseSpark.y = stage_protonCore.y;
}
An easy solution would be to disable the mouse for those children when you create them:
fuseSpark.mouseEnabled = false;
That is, ofcourse, only if you don't care if the user can click those elements.

MoveClip.Visible and MouseEvent - ActionScript3

Say I have the following;
public function onBellyPatch_Two(e:MouseEvent):void
{
inBelly_Two.visible = true;
}
inBelly_Two is a MovieClip
I have two movieclips over top of each other, when you click one MovieClip another one shows up on top, and when you click that (second MovieClip)a textBox is updated.
I noticed that even if a movieclip object's visible property is false, when you click in the area where the movie clip is the MouseEvent.CLICK event is called. Is there a way to get around this? I would like to stack movieClip.
I guess one way to get around this problem would be:
removing the eventListener when movieClip is not visible and enabling the eventListener when moviclip is visible.
Is there some otherway?
Much Thanks,
Mike
Try adding:
inBelly_Two.buttonMode = false;
This will let onBellyPatch_Two be called no matter if inBelly_Two is visible or not.
Instead of removing the listener, you can just say
mc.mouseEnabled = false;
mouseEnabled docs