External Interface and local connections
External interface is a class in Flash that allows the swf to talk to javascript and vice versa. There a two basic methods:
- call - you can call a javascript function from the swf
- addCallback - you can call a actionscript function from javascript
So to get it to work first of all you need to import the External Interface class:
import flash.external.ExternalInterface;
Then you need add your calls and callbacks. For a callback:
ExternalInterface.addCallback("actionScriptFunc", this, actionScriptFunc);
In this case the actionScriptFunction in the inverted commas is the name that the javascript will be calling and the second is the function within the actionscript itself. The ‘this’ bit as I understand it refers to the movie itself but I not sure you should worry about it at this stage unless you want to learn a bit more about OOPs. This actionscript function needs to have all the correct parameters as it is call from the javascript e.g.
The javascript:
actionScriptFunc(param1, param2);
The actionscript:
function actionScriptFunc(param1:String, param2:String):Void{
if(param1 && param2){
doStuff();
}
}
So basically you are sending param1 and param2 into the swf so actionScriptFunc can do what it wants with it.
And for a call:
ExternalInterface.call("javascriptFunc", this, param1, param2);
This calls the javascript function ‘javascriptFunc’ with the param1 and param2.
So the javascript function might look like this:
function javascriptFunc(param1, param2){
doStuff(param1, param2);
}
Once you get your head round you should be able to easily send stuff between swfs and javascript. N.B. This only works in Flash Player 8.
The good thing about this is if you want to use a Local connection between two movies it provides a way for you to give the ‘connections’ unique ids so you movies only talk to each other and you can have more than one set of movies running at a time.
To do this you need functions in the movies to set the names of the local connections. You need a sender and a receiver for each movie so you need to set names for these connections. This means the connection name needs to be a variable e.g.
sendingLC.send (senderName);
receivingLC connect( receiverName );
Then there will be two functions in each movie one that sets the senderName and one that’s sets the receiverName. In each movie the connection names are swapped so movie 1 will have the same senderName as movie 2s receiverName and vice versa.
Each of the two functions should set up so it can be called from javascript using the External Interface object sending in randomly generated names/numbers. I try and give them a name that identifies which connection is which so when I am debugging I can see which names are set where. to generate the names I use a fixed name say ‘movie1′ and appeand a random number using something like:
var random_number = Math.round(Math.random()*10000000);
You should really be able to set up the connections without using javascript by using one named connection between the two movies which is only used to send the ids across. I tried doing this originally without much success hence this idea which I have working and seems pretty reliable as well!

This is exactly what I was looking for, thanks for the great information.