Hi,
If both are running on the same local computer, then this can be achieved with LocalConnection Class. In your first Flash file, have this on your Frame Actions:
Actionscript Code:
var sendMessage:LocalConnection = new LocalConnection();
sendMessage.send("transferName", "onMessageReceived", "this message was sent");
and on your Second Flash File, create a Dynamic Textfield, give it an instance name of,
txt, and have this on your Frame Actions:
Actionscript Code:
var receiveMessage:LocalConnection = new LocalConnection();
receiveMessage.onMessageReceived = function(theMessage){
txt.text = theMessage; // will display 'the message was sent'
}
receiveMessage.connect("transferName");
Make sure you first open the SWF Flash file with the textfield, and THEN the send SWF file, because the sending signal will only be sent once, and we want our receiving SWF file to be present when the signal is sent, to catch it.
Now, how does this work? Well, let's break it down, firs the sending code (the first code). We are creating a new LocalConnection object called sendMessage, and then we're using LocalConnection's send() function to send a message. This send() function's parameters are comprised of, send(
the signal name,
the function's name,
additional parameters)
the signal name - this is important, and can be named whatever you want, because this is the unique ID of the signal you're sending. Whichever flash file which wants to receive the message, must specify the signal's name, because there are certainly other SWF file's open, and the signal can't be sent to every single one.
the function's name - this is the function's name, which the receiving SWF file can receive and its corresponding parameters. Say, if you wanted to categorize your message sent to another SWF file, like, you'd like to send a color, a car, and a cake (sorry for lack of better example:P), then you could send 3 functions, one for each item.
additional parameters - this is where the real message is sent, as the above function's parameters. Continuing on the bad example from above, you'd probably like to know what color, what car and what kind of cake was sent, so you send parameters with the function, which the receiving SWF can utilize.
Let's create a new sending SWF from the bad example from the above explanation (lol:P). We'd like to send a color, a car's brand name and color, and a type of cake with its fruit topping and main content. Let's write the code:
Actionscript Code:
var sendMessage:LocalConnection = new LocalConnection();
sendMessage.send("uniqueID", "getColor", "Green");
sendMessage.send("uniqueID", "getCar", "Ferrari", "Red");
sendMessage.send("uniqueID", "getCake", "Chocolate Cake", "Strawberries", "Chocolate");
Now, let's move on to the receiving SWF, and while having 3 Dynamic Textfields with the instance names, txt1, txt2, txt3, let's write the receiving code on our Frame:
Actionscript Code:
var receiveMessage:LocalConnection = new LocalConnection();
receiveMessage.getColor = function(theColor){
txt1.text = "The sent color is: "+theColor;
}
receiveMessage.getCar = function(brandName, carColor){
txt2.text = "I have a "+brandName+", and its color is "+carColor;
}
receiveMessage.getCake = function(cakeType, fruitTopping, mainContent){
txt3.text = "I just baked a "+cakeType+", and decorated it with "+fruitTopping+" on top. Did you know that "+cakeType+" is coated with "+mainContent+"?";
}
receiveMessage.connect("uniqueID");
So, we're creating a new LocalConnection instance, and then we're creating 3 functions in it, getColor, getCar, and getCake, the 3 functions we declared in our sending SWF, remember? In the brackets after the keyword,
function, you declare the number of parameters sent for that particular function, and you can name them whatever you want. For instance, for getColor, we only sent 1 string, which was the color name, thus in the getColor function in our receiving SWF, we specify 1 parameter for the received color and we can name whatever we want it. Then, we can use the named parameter inside the function to refer to the sent value. In this case, we sent "Green" as the parameter's value, and in the receiving SWF, we've named that parameter, theColor. Now, in our getColor function, we can use, theColor, to refer to the sent string, which is "Green". If you created 3 textfield, then in the first textfield, you'll read, "The sent color is: Green". The same goes for the 2 other functions and their parameters.
The last code tells the receiving LocalConnection instance that it will catch the signal named, uniqueID, and all of its sent messages (functions and their parameters).
Hope this helps :)