AS3:向加载的 swf 添加事件侦听器 [英] AS3: add event listener to loaded swf
问题描述
我正在尝试从我加载的 SWF 中侦听自定义事件,但我无法捕获它.现在的加载代码只是:
I'm trying to listen for a custom event from an SWF I've loaded and I'm just not able to capture it. The loading code right now is just:
public function loadGame(gameSrc:String,gX:Number,gY:Number):void {
var loader = new Loader();
var addedDefinitions:LoaderContext = new LoaderContext();
addedDefinitions.applicationDomain = new ApplicationDomain();
loader.load(new URLRequest(gameSrc));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoaded);
function onLoaded(evt:Event):void {
var game:MovieClip = MovieClip(evt.target.content);
game.x = gX;
game.y = gY;
chamber.mc_gameHolder.addChild(game);
Tweener.addTween(chamber.mc_gameTitle,{alpha:1,time:.75});
game.addEventListener("showQuiz",showQuiz);
}
}
我知道该事件是从我加载的 SWF 中触发的,因为我还有一个侦听器,可以在触发时跟踪hello".
I know the event is being fired from my loaded SWF because I also have a listener in there that traces out a "hello" when it's fired.
有人吗?如果之前已经发布过,请道歉 - 搜索没有发现任何具体内容.
Anyone? And apologies if this has been posted before - search didn't turn up anything specific.
推荐答案
我遇到了同样的问题.这是您需要做的.实例化 LoaderContext 时,请确保 LoaderContext 使用的是 SecurityDomain.currentDomain.这将解决您的问题.
I ran into the same problem. Here is what you need to do. When instantiating your LoaderContext, make sure the LoaderContext is using SecurityDomain.currentDomain. That will solve your problem.
这篇关于AS3:向加载的 swf 添加事件侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!