views:

2188

answers:

3

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.

A: 

Create 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.

Gordon Potter
I don't have control over the ActionScript of the underlying movie. It does its own thing and I'd like to stop it from doing it.
Jon
Also, that code is AS3 specific and will not work with AS2.
Branden Hall
+1  A: 

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.

Branden Hall
I like this idea and I added a movieclip that's above the swf I'm loading but even after every mouse related event I can think of the clip is still catching my onrelease events.
Jon
Well, I'm positive this technique works - I use it all the time! You need to make sure that the movieclip is visible (blocker._visible = true). You may want to add some actual color to the fill to make sure that you are, in fact, above the loaded SWF since it's easy to get the depth wrong with AS2.
Branden Hall
Yeah I've used it too. I made my blocker clip contain a large blue rectangle so I'm very certain it's being loaded and at the right width and height. If you're interested the assets that are giving me the biggest headaches are from Print2Flash.
Jon
A: 

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.