Short thoughts by David LeMieux
ALERT: This post is going to get a little nerdy. Proceed with caution.
Adobe provides in the AVM (ActionScript Virtual Machine) a means to create connections between multiple instances of AVM or Flash file. In both AVM1 and AVM2 (AVM1 runs AS 1-2; AVM2 runs AS 1-3) this object is called LocalConnection. A local connection can be very handy.
If you've ever been to the Amazon.com MP3 store you can see a very practical example. Each song has a play button that tells a central media player which track to play. Instead of embedding multiple multimedia players and using excess bandwidth and system memory you can have many disconnected buttons control on main piece. This is especially useful when you realize that otherwise you could have 10-20 sound clips playing simultaneously, providing a bad user experience.
Another HUGE benefit of the LocalConnection option is that it is location agnostic. You can have one Flash player on a popup, in an iFrame, or running locally and use a local connection to connection to a Flash player on another window, iFrame or popup. This makes connecting (as the name would imply) multiple windows easy. If you pair LocalConnection with ExternalInterface (a way to call JavaScript function from withing the AVM) you can create a useful bridge between embedded content and page content.
Recently, while working on a project for work, my co-worker and I ran in to some issues around LocalConnection that would could not figure out. After much hair pulling and stress we determined that LocalConnection has undocumented limitation, or in other words, a bug. When the AVM makes the LocalConnection object it seems to only allocate a small amount of memory or system resources because it can easily become overloaded. To show an example, I have put together a simple test page: LocalConnection Test Page. The swf on the left is a receiver listening for connections on a channel. When you click the "Add Sender" button on the right you add a sender to the screen that begins to connect to the receiver. If you make too many or too many too quickly you will see that some of them will begin to fail. The receiver never seems to stop, but the senders stop working. Unfortunately, they fail silently. For whatever reason the failing local connections aren't firing their "onError" status events. Nothing happens, they just stop.
Once we discovered this limitation we stopped pulling our hair out. After searching the Internet we found that others are having similar problems, but none exactly like ours (Our problem was more related to multiple simultaneous connections). So for everyone out there - YES, LocalConnection has a multiple connection issue. If I had to guess, I would say that it involves a race condition, it isn't "thread" safe, and it has limited memory allocated to it. (On that note, it would be cool if Flash had threading.)
Lets hope that in the future Adobe addresses this issue with Flash player 10. In the mean time we are working on a solution using SharedObject and timed polling. We are hoping to use a queue of instructions to duplicate the utility of LocalConnection. Those savvy to the situation will know where we are headed. Others can feel free to ask in the comments.