Hi !
Did it happen to you to assign a mouse event to a MovieClip (such as MouseEvent.MOUSE_DOWN) and realise that it does not comport itself as expected?
It acts as if no event was associated to it?
Certainly, you have another MovieClip above it which blocks the mouse event.
If you have encountered this problem and you could not find the answer, I have the solution for you.
The trick is in the property mouseEnabled of the InteractiveObject Class (also available from the MovieClip class being a subclass of InteractiveObject).
Let us say that I have a MovieClip named ‘clip_mc’ and on a higher level, I have another MovieClip with alpha 50 that covers clip_mc.
In this case, all the events associated to clip_mc are cancelled by the MovieClip on top of it.
To resolve this problem, we can simply add to the top MovieClip .mouseEnabled=false;
Let us take a look at a concrete example…
I create a MovieClip, I assign to it the instance name ‘clip_mc’ and I assign to it the event MOUSE_DOWN so that each time it is clicked a text field returns ‘ok’:
Code:clip_mc.mouseChildren=false; clip_mc.buttonMode=true; clip_mc.addEventListener(MouseEvent.MOUSE_DOWN,go); function go(evt:MouseEvent):void { debug_txt.appendText('ok'+'\n'); }
Nothing strange. Everything works as it should and when I click, the text field acts as it should as the event is intercepted.
Next, I add the second MovieClip with an instance name ‘over_mc’ on a higher level then clip_mc, keeping the same event associated to clip_mc (the same code)
There it is that clip_mc does not intercept anymore the event MOUSE_DOWN. In fact, if I click, nothing happens…even the hand mouse has disappeared.
This is due to ‘over_mc’ which has by default a property mouseEnabled set to true and hides the mouse event associated to clip_mc.
To resolve the problem, we will need to impost the mouseEnabled to false for over_mc, the following way:
Code:over_mc.mouseEnabled=false; clip_mc.mouseChildren=false; clip_mc.buttonMode=true; clip_mc.addEventListener(MouseEvent.MOUSE_DOWN,go); function go(evt:MouseEvent):void { debug_txt.appendText('ok'+'\n'); }
Now, if I click on clip_mc everything is back as it should be.
Stay tuned !
Bookmarks