LocalConnect is extremely useful, especially these days since it's a very good way for an AS3 app to talk to an AS2 app. They can't communicate directly - but you can probably get around that with LocalConnect. But there is a pernicious bug that will leave you scratching your head if you aren't aware of it. As luck would have it, I'm about to tell you how to fix it.
With LocalConnect, you have a sender and a receiver. The receiver broadcasts his intentions to be a receiver by first instantiating the LocalConnection object, then calling the "connect" function like this:
var rcvConnection:LocalConnection = new LocalConnection();rcvConnection.connect("myHandle");Meanwhile, the sender has also instantiated a LocalConnection object in the same manner:
var sndConnection:LocalConnection = new LocalConnection();And when he wants to talk to the receiver he simply calls the send method like this:
sndConnection.send("myHandle", "nameOfFuncInReceiver", "param1", "param2");The killer bug arises if there are two or more receivers that are using the same handle. The sent message will be consumed by one
and only one of the receivers. So if it's not the receiver you're expecting to get the message you're sitting there wondering "where is my freaking message?" Well, your freaking message was consumed already and you'll never get it.
Solution:When you instantiate your Flash objects (using swfobject, of course), you will pass each SWF (sender and receiver) a random number (the same random number) generated at runtime using JavaScript. When the receiver broadcasts his handle, he now appends the random number to the string so that the handle becomes - "myHandle_1234567".
Likewise, the sender uses the same random number to append to the string he uses to call the receiver. So the send call becomes:
sndConnection.send("myHandle_1234567", "nameOfFuncInReceiver", "param1", "param2");Problem solved!