1
votes

I have a flash browser application that loads in a child swf using a Loader object.

The child swf has a mouseclick listener that calls nativateToUrl, and opens a new web page. It also contains mouse hover events that make things in the swf move around.

This application that does the loading is like a container for the child swf and should open a different web page when it is clicked. So essentially I want to suppress the child swf mouseEvent and listen for the mouse click on the container swf, opening the new URL.

I have heard of other people putting an invisible sprite over the original content so that the child swf doesn't actually catch a mouseclick event. However, this won't work in my case because then it doesn't get the mouse hover events either. I want the mousehover events to go through and make the things in the child swf move but also suppress the click event.

So, for all the flash masterminds out there... is this possible? And how can I do it?

:) thanks.

1

1 Answers

1
votes

If you want to suppress all MouseEvent.CLICK events from reaching a loaded SWF, you can do the following:

Let's assume you have the following setup:

var loader:Loader = new Loader();
loader.load(new URLRequest("child.swf"));
addChild(loader);

What you can do, is listen on the capture phase for a click event on the Loader:

loader.addEventListener(MouseEvent.CLICK, handler, true);//the third parameter (true) tells flash to listen on the capture phase of an event's lifecycle

Then in the click handler from that, cancel the event so it doesn't propagate down to the loaded SWF:

function handler(e:Event):void {
    e.stopImmediatePropagation();
}

If you don't understand the phases of events, this diagram from Adobe may help:

enter image description here

Source

As an aside, if you wanted to suppress all mouse stuffs from the SWF, a much better way (instead of adding an invisible sprite) is to just do this:

loader.mouseChildren = false;