views:

39

answers:

2

Hey guys I'm having such a hard time of it today.

I have a game, I've loaded into a parent SWF -

I would like my parent SWF to accept events I dispatch from within the game, or have the ability to talk both ways.

-- Reason is, I would like to unload and load the game back in, once the end screen is active.

Any help and I'll give you beer.

thanks in advance.

A: 

can't you put in your parentSWF:

childSWF.addEventListener(MyCustomEvent.SOME_EVENT, listener) and just dispatch the events from the game?

As for talking the other way, it can call childSWF.someFunction() to call functions in the document class of childSWF, etc.

jonathanasdf
is it really that simple? When I dispatched the event from the child, I found I could not accept them in the parent. Where would I dispatch the event from inside the child? is it the Document Class? And listening to the same child in the parent I have to listen on the object itself - not a property like "childSWF.content"?
Glycerine
I had assumed you had `childSWF = loader.content as MovieClip` already. and it should work no matter where you dispatch the event from, as long as it isn't canceled and it bubbles.I had read somewhere that the swfs may have to be in the same application domain or something. Hopefully that's not the case, as that gets a lot more complicated.
jonathanasdf
actually, seems you might want to look into Loader.sharedEvents: http://richardleggett.co.uk/blog/index.php/2009/04/02/loading-swfs-into-air-1-5-and-loaderinfo
jonathanasdf
Nice one. Seems to be exactly what I'm looking for.
Glycerine
A: 

Are the events dispatched by your game allowed to bubble up to your loader swf? The default value for the Event constructor sets this to false. If you were to set it to true, however, an event dispatched by a child swf would make it to its parent's listener.

For example: this.dispatchEvent(new Event("SOME_GAME_EVENT", true, true));

The first 'true' value says that the event should bubble up through the object hierarchy. The second says that the Event is cancelable. Once your loader swf has handled the Event, it is best to then call .stopPropagation() on the event so it does not further bubble unneccessarily.

turkeyburger
Thank you - it worked. I can now capture at the parentSWF level events dispatched by the game.Bonus of this method is there is no SWF coupling - therefore GC'ing the childSWF later works well.thanks again TurkeyBurger
Glycerine