I have SWF files that I load into my flash movie and those SWF files sometimes have mouse events that can interfere with dialogs and buttons in my flash movie. I'd like to temporarily disable the loaded SWFs mouse event handlers or block them from having any effects on my flash movie. My flash movie is AS 2.
views:
2188answers:
3Create your event handler at the moment it is actually needed such as the when the button or object comes on the frame.
If the event listener mouse clicks has already been created you can remove the listener at any time in actionscript.
myButton.removeEventListener(MouseEvent.CLICK, handleMouseClick);
And then have a function or related logic turn the mouse event handler back on later
myButton.addEventListener(MouseEvent.CLICK, handleMouseClick);
"handleMouseClick" being the actual function and code that does something with the mouse click
Another solution is to set some global boolean flag in your actionscript on your main timeline and then inside the functions that handle mouse functionality you can first check for the boolean before doing anything. The mouse event will still be created and passed to your event handler but can be selectively ignored depending on the state of your boolean flag.
A common solution to this kind of problem in ActionScript 2 is what is often called a "blocker" clip. Simply create a movieclip that consists of a fully transparent fill. Then you can place this movieclip where ever you want and size it as needed. Finally you assign this clip a dummy mouse event and turn off it's use of the hand cursor - like this:
blocker.onRelease = function() {};
blocker.useHandCursor = false;
As long as this clip is above your loaded content, it will absorb any mouse events.
As the other answers state, the way to stop click events from reaching a child SWF is to place a blocker object in front of it. The key is for the blocker to be a button. A simple clip with a shape will still let clicks through to AS2 child SWFs.
The blocker button is needed even when either an AS2 or AS3 parent is loading an AS2 child SWF.