views:

661

answers:

4

ok, maybe i've just had too much beer at this point but - i'm just trying to listen for a custom event from a 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've tried like a ton of ways to do this and NONE of them work. 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.

+1  A: 

This would work only if both SWFs are AVM2Movie (made using AS3), which I assume is the case here because otherwise casting to MovieClip would have thrown an error on run-time.

Are you sure that the event is dispatched by the document class of the loaded swf and not by one of its children? Because you are calling addEventListener on game which is the document class (root) of the loaded SWF and it won't catch events dispatched by its children. Can you show the code where you dispatch the event?

Amarghosh
A: 

It may be possible that the event is being dispatched before the Event.COMPLETE event. Try adding a listener for the Event.INIT event. The Event.INIT event is dispatched when the Loader first has access to the loaded swf's document object.

Chris Gutierrez
A: 

hm, shouldn't it be :

addedDefintions.applicationDomain = ApplicationDomain.currentDomain to permit the loaded video to 'access' the parent one ?

Also for testing purposes I suggest to bubble the event up to make you haven't missed out a display object in between.

Theo.T
+1  A: 

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.

mdemmitt