好的,我有一个flash浏览器应用程序,它使用Loader对象加载子swf。我原以为向Loader对象添加一个鼠标单击侦听器将允许我侦听对象上的单击,但事实并非如此。:/
我真的看到点击了!!当我在IDE (Flash Develop)中测试时,被追踪出来。但是,在任何浏览器中都不会调用鼠标处理程序。有人知道为什么会这样吗?
此外,试图访问加载器对象的子对象会导致安全沙箱错误。
public function Main()
{
trace("Starting...");
Security.allowDomain('*');
Security.allowInsecureDomain('*');
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
var inputFlashVars:Object = this.loaderInfo.parameters
_swfLoader = new Loader();
stage.addChild(_swfLoader);
_swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSwfLoaded);
var ldrContext:LoaderContext = new LoaderContext(true);
ldrContext.checkPolicyFile = true;
ldrContext.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
//ldrContext.applicationDomain = new ApplicationDomain(new ApplicationDomain());
var urlForVideoToPlay:String = AD_SWF_URL;
trace("Loading swf: " + urlForVideoToPlay + " with click URL: " + CLICKTHROUGH_URL);
_swfLoader.load(new URLRequest(urlForVideoToPlay), ldrContext);
}
private function onSwfLoaded(e:Event):void
{
//var swfChild:* = _swfLoader.getChildAt(0);
//_swfLoader.mouseChildren = false;
trace(e.target);
_swfLoader.stage.addEventListener(MouseEvent.CLICK, onInnerSwfClicked, false);
_swfLoader.stage.addEventListener(MouseEvent.MOUSE_DOWN, onInnerSwfClicked, false);
_swfLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onSwfLoaded);
trace("Ad swf loaded!");
}
private function onInnerSwfClicked(e:Event):void
{
trace("clicked!!!");
e.stopImmediatePropagation();
}
我认为错误来自于您的点击侦听器,您将它们附加到错误的舞台对象:
_swfLoader.stage.addEventListener(MouseEvent.CLICK, onInnerSwfClicked, false);
_swfLoader.stage.addEventListener(MouseEvent.MOUSE_DOWN, onInnerSwfClicked, false);
当你在父swif中加载子swif时,阶段指向父swif。它在调试模式下工作,因为你正在加载子swift而没有shell/parent。
试试这个:
_swfLoader.content.addEventListener(MouseEvent.CLICK, onInnerSwfClicked, false);
_swfLoader.content.addEventListener(MouseEvent.MOUSE_DOWN, onInnerSwfClicked, false);