views:

2778

answers:

2

I have a main .fla file that I am using to load a sequence of three games. If the user wins a game, they go on to the next game. Is it in any way possible to pass to the main project whether the user has won the game? I have tried using loader.content, but that does not seem to be working. I am using Flash CS3.

+2  A: 

You can pass data to and from loaded swfs no problem. What it sounds like you are trying to do is communicate from the loaded swf to the loading swf. The ideal way to do this is to dispatch an event on the loaded swf and listen for it in the loading swf. Roughly (not tested it because i'm in a rush) you need something like this. Load the swf. Have a load complete handler. Get the content of the loader and listen to a custom event. You can pass whatever you want on this custom event.

var myLoader:Loader = new Loader(); 
var url:URLRequest = new URLRequest("myExternalMovie.swf"); 
myLoader.load(url);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(event : Event)
{
    var contenet : MovieClip = event.target.content;
    content.addEventListener(yourGameEvent.GAME_COMPLETE, yourGameEventHandler);

}

If you've never used custom events before check this link (or google for more)

http://www.adobe.com/devnet/flash/articles/creating_events.html

As a disclaimer thats the quick way to get the data into you main class. Personally i'm not a massive fan of passing data in events. I'd rather fire a empty event and the get data from properties of the firing object)... but that's just a personal preference.

James Hay
A: 

Use the LocalConnection class

Kenny Phan