Jon
Jon

Reputation: 2085

Flash: How can I Disable or block all mouse events temporarily for an externally loaded SWF

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.

Upvotes: 3

Views: 12714

Answers (4)

Devyn
Devyn

Reputation: 2275

You may also use a variable and check whether the state is '0' changed whenever clickEvent function is called.

var lockScreen:int = 0;

Set lockScreen = 1 when you want to ignore click events and set back to Zero after doing something. At least it works for me :)

Upvotes: 0

anthonysapien
anthonysapien

Reputation: 77

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.

Upvotes: 0

Branden Hall
Branden Hall

Reputation: 4468

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.

Upvotes: 5

Gordon Potter
Gordon Potter

Reputation: 5862

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.

Upvotes: 0

Related Questions