Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
601 views
in Technique[技术] by (71.8m points)

actionscript 3 - AS3: add event listener to loaded 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);  
}

}

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...