好的,我有一个flash浏览器应用程序,它使用Loader对象加载子swf。我以为向Loader对象添加鼠标单击侦听器可以让我侦听对象上的单击,但它不是这样的。:/
我真的看到点击了!当我在我的IDE (Flash Develop)中测试时被跟踪出来。但是,当放入任何浏览器中时,鼠标处理程序永远不会被调用。有人知道为什么会发生这种事吗?
此外,尝试访问加载器对象的子级会导致Security Sandbox错误。
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();
}发布于 2015-07-10 23:23:19
我认为错误来自于您的点击监听器,您将它们附加到了错误的stage对象:
_swfLoader.stage.addEventListener(MouseEvent.CLICK, onInnerSwfClicked, false);
_swfLoader.stage.addEventListener(MouseEvent.MOUSE_DOWN, onInnerSwfClicked, false);在父swif中加载子swif时,舞台指向父swif。它在调试模式下工作,因为您加载子swif时没有shell/父。
试着这样做:
_swfLoader.content.addEventListener(MouseEvent.CLICK, onInnerSwfClicked, false);
_swfLoader.content.addEventListener(MouseEvent.MOUSE_DOWN, onInnerSwfClicked, false);https://stackoverflow.com/questions/31342720
复制相似问题