Copy link to clipboard
Copied
Hi, recently I'm working on a project to parse and show the VAST3 ad. One thing I need to do is listen for the MouseEvent.CLICK on the loaded SWF file.
I added the loader to a sprite and add the event listener on the sprite. When I load the following SWF file, the click event fires only when I click the background. If I click on the site logo, no click event happens.
If I downloaded the SWF file to my local hard drive, everything works fine. The click event can be fired wherever I click on the ad.
The SWF that I load has all the assets embedded.
I want to find out what's causing this problem because with some SWF files I can only listen to the MouseEvent.CLICK event on the _loader.content whereas some like the one below, partially responds to click event on _loader.content and _container.
I simplified the code as listed below.
package {
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.net.URLRequest;
public class Main extends Sprite {
private var _container:Sprite;
private var _loader:Loader;
public function Main() {
_container = new Sprite();
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
_loader.load(new URLRequest("http://gtms04.alicdn.com/tps/i4/TB1Fzd.FVXXXXaOXXXXeflbFXXX.swf"));
_container.addEventListener(MouseEvent.CLICK, onClicked);
addChild(_container);
}
private function onComplete(event:Event):void {
_container.addChild(_loader);
_loader.content.addEventListener(MouseEvent.CLICK, loadedSwfClicked);
}
private function loadedSwfClicked(event:MouseEvent):void {
trace("loaded swf clicked"); // When I click on the Logo and the animal
}
private function onClicked(event:MouseEvent):void {
trace("clicked"); // When I click on the gradient background
}
}
}
One of my colleagues told me that it has something to do with the Security issue. So I need to do a Security.allowDomain call like this:
private function onComplete(event:Event):void {
Security.allowDomain(_loader.contentLoaderInfo.url);
_container.addChild(_loader);
//_loader.content.addEventListener(MouseEvent.CLICK, loadedSwfClicked);
}
And the click on the loaded SWF will bubble up properly.
Because the gradient background layer of the loaded SWF only contains a Bitmap, which is not an
...Copy link to clipboard
Copied
I am not sure why the _container listener gets overridden by the child, but it can be cured to only listen to teh _Container being clicked if you disable its mousechildren property...
private function onComplete(event:Event):void {
_container.addChild(_loader);
_container.mouseChildren = false;
_loader.content.addEventListener(MouseEvent.CLICK, loadedSwfClicked);
}
Copy link to clipboard
Copied
Thanks Ned. Well, this solution works great if the loaded SWF doesn't contain any interaction like the one in my sample code. But I don't know whether the loaded SWF is user intractable in the production environment. I'll be much appreciated if someone could tell me why the click event listener is not working on some portions of _container or _loader.content.
Copy link to clipboard
Copied
You need to be able to look at the code for the loaded swf to see what listeners are assigned that can bubble up and interfere with the parent. Normally when you assign a mouse-related bit of code to a parent, the children are blocked from access. In this case, something of the child is overriding that - you need to see the code in the child.
Copy link to clipboard
Copied
I asked the designer about the structure of the SWF above and recreated a much simpler one.
Just a simple SWF without any ActionScript.
There are only 2 layers: The background layer, which is a Bitmap Image and the text layer, which is static text being break apart as drawings and then wrapped in a MovieClip.
Replacing line 18 of the sample code with:
_loader.load(new URLRequest("http://img03.taobaocdn.com/tfscom/TB1BIydFVXXXXbJXXXXeflbFXXX.swf"));
Still the same problem
Copy link to clipboard
Copied
One of my colleagues told me that it has something to do with the Security issue. So I need to do a Security.allowDomain call like this:
private function onComplete(event:Event):void {
Security.allowDomain(_loader.contentLoaderInfo.url);
_container.addChild(_loader);
//_loader.content.addEventListener(MouseEvent.CLICK, loadedSwfClicked);
}
And the click on the loaded SWF will bubble up properly.
Because the gradient background layer of the loaded SWF only contains a Bitmap, which is not an instance of InteractiveObject, it won't respond to the MouseEvent.CLICK listener on the _loader.content.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now