Archive

Archive for February, 2007

Unique LocalConnection in Flash using Javascript

February 12th, 2007

I’ve been working on a project that has a number of flash objects communicating with eachother in a web page. I implemented all of the LocalConnection stuff and it worked beautifully but with one rather significiant outstanding issue: when I opened multiple instances of the web page in a browser flash started act pretty strangely. This isn’t all too supriseing, the LC connection has to have a name and both flash objects must be set to listen in on that name – if you open more than one instance now you have two LocalConnection objects communicating on the same channel. Initially I thought a solution to this would be to use Actionscript to tack on a time based unique identifier to each localconnection object in both swf’s respectively – but since there is no guarantee that both are going to run at precisely the same time then this could potentially lead each swf to generate a different timestamp and consequently try to communicate on two different channels.

My solution to this was to use Javascript to generate a unique identifier . When the <body> tag loads it generates a timestamp and passes it into all flash objects using addVariable() (via swfObject). The LocalConnection id for all flash movies is input from this single source therby ensuring that all have the same unique identifier.

See it in action here

Download: Unique LC as a zip file

*Note: these example files were made within the Flash 8 IDE

ian News