Creating a Movieclip that is masked, you can click and respond to MouseEvents

This question is a continuation of the questions at the link: Creating a Movieclip that is set as a mask is clickable and responds to MouseEvents

The structure of your layers that I have on stage looks like this:

  • holder_mc

    • dragCanvas_mc
    • mask_mc
    • canvas_mc

dragCanvas_mc - used to pan the belly button.

mask_mc - Mask for canvas_mc

Now I am facing a problem. I cannot register MouseEvents on canvas_mc

This is necessary because I need to make drawings on canvas.

holder_mc.canvas_mc.addEventListener(MouseEvent.MOUSE_DOWN,onStartDrawing); function onStartDrawing(evt:MouseEvent) { trace("Hello"); } 

I do not see Hello in the output window. Any idea where I'm wrong. Thanks in advance.

+1
source share
2 answers

If “MovieClip A” is above “MovieClip B” in the display list and “MovieClip A” is “mouseEnabled”, then “MovieClip B” will never receive events “through” the top clip.

In your case, the drag canvas is higher and most likely tied to some mouse events. If this is the case, you need to handle the events using the top clip (drag and drop canvas) and pass them to the children or the parent holder_mc.

 holder_mc.addEventListener(MouseEvent.CLICK, onClick); function onClick(e:MouseEvent):void { // do normal clicky stuff for this object // then.. // if(canvas_mc.hitTestPoint(mouseX, mouseY, false)) { // do clicky stuff for canvas mc } } 

Some people may say that they use 'getObjectsUnderPoint', but there is a documentary error associated with it, so use hitTestPoint () http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html # hitTestPoint% 28% 29

+1
source

Maybe your mask_mc intercepts mouse events. You can try this test to find out who shoots MouseEvent.CLICK .

 holder_mc.addEventListener(MouseEvent.CLICK,whoFiredTheEvent); function whoFiredTheEvent(e:MouseEvent){ trace(e.target.name + " fired the event"); } 

If it is mask_mc or some other clip, you can set mouseEnabled to false for this movie clip, and MouseEvent ignore it.

+1
source

Source: https://habr.com/ru/post/1400481/


All Articles