I need to make sure that only one instance of a SWF is open at any one time on a computer, whether it is in 2 browser windows, or two different browsers.
How can I go about doing it?
I have so far thought of two potential solutions:
1) Using a Flash sharedobject – but since they never expire, if the user closes the browser window without calling my quit function to remove it, the remaining object will interfere with other new sessions. (Perhaps a random number and timestamp to identify the instance?)
2) Using a localconnection – a bit hackish, this relys on the swf detecting whether a Localconnection object is being used, and not loading if that is the case. But localconnections seems to crash at the slightest provocation, so I am a bit wary of using it.
I believe LocalConnection has one advatage over SharedObject solution – it allows global-scope LocalConnection names, though local SharedObjects are always stored per-domain, as far as I know.
As for SharedObject, the only option is to keep regularly updated timestamp in it, and check it every time your .swf runs.
So I’d opt for a simple LocalConnection-based solution, because it’s quite straightforward, and I’ve never experienced any problems with LocalConnection.