好的,我有一个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();
}
答案 0 :(得分:0)
我认为错误来自您的点击侦听器,您将它们附加到错误的舞台对象:
_swfLoader.stage.addEventListener(MouseEvent.CLICK, onInnerSwfClicked, false);
_swfLoader.stage.addEventListener(MouseEvent.MOUSE_DOWN, onInnerSwfClicked, false);
当您在父swif中加载子swif时,舞台指向父swif。它适用于调试模式,因为你在没有shell / parent的情况下加载子swif。
请改为尝试:
_swfLoader.content.addEventListener(MouseEvent.CLICK, onInnerSwfClicked, false);
_swfLoader.content.addEventListener(MouseEvent.MOUSE_DOWN, onInnerSwfClicked, false);