Flash man by Zerofractal Studio
Imagine this. You have a stand-alone video player that you want to bring into a larger project (via movieclip loader). What if you want the background of your main project to lighten when a user clicks play, so it isn’t distracting? With two separate .swf files, actionscript provides the ability to “talk” easily between one another after creating a LocalConnection. In our example, the video player will be called the sender and the main file will be called the receiver. This LocalConnection class works regardless of browser or actionscript language. For instance, you could write the video player in AS3 and look at it in Firefox, while the main file is programmed using AS2 and in IE, and it will still work. WOW.
After doing some research, here is the best tutorial for SWF intercommunication, with step-by-step directions in both AS2 and AS3 and accompanying files. Their example shows how to transfer text from one file to another. But, it is important to realize that you can also send commands and other actions (gotoAndStop … ._alpha … .visible … ._x … etc).
To communicate text strings: (files found in the tutorial)
Sender:
var outgoing_lc:LocalConnection = new LocalConnection();
send_btn.onRelease = function() {
outgoing_lc.send(“lc_example”, “methodToExecute”, userMessage_txt.text);
}
Receiver:
var incoming_lc:LocalConnection = new LocalConnection();
incoming_lc.connect(“lc_example”);
incoming_lc.methodToExecute = function(param:String) {
sentMessage_txt.text = param;
}
In our video player example, the code would be as follows:
Sender:
var outgoing_lc:LocalConnection = new LocalConnection(); //establish a connection
//when you click on the play button, do something
playBtn.onRelease = function () {
outgoing_lc.send(“moviePlay”, “lightenBackground”); // tell the main file to lighten the background
}
Receiver:
var incoming_lc:LocalConnection = new LocalConnection(); // establish the connection
incoming_lc.connect(“moviePlay”); // read the connection from the sender message
//whatever you put inside the function will happen when the user clicks the play button
incoming_lc.lightenBackground = function(param:String) {
backgroundMC._alpha = 50;
}
Here is the result: (please overlook the design, or lack thereof!) Download the files HERE. Hope this was helpful! Let me know if you have any questions.
Some problems with download. I suppose this is because I work with IE 6.0.