0

I think I've found a flash bug with the LocalConnection communication setup, such as described here. The site below is not mine, I'm just using it to show that the problem also occurs on other sites:

How to reproduce:

http://fcontheweb.com/articles/localconnection/

If you open the site in 2 browser windows, find the as3 example that sends a message between 2 as3 components.

Click the button in the first browser window: it will communicate locally with the message box. If you then press the button on the second browser window, nothing will happen. If you close the first browser window, you have to refresh the page before things start working for the second window.

I think this is because the namespace of as3 objects in both windows are overlapping in the flash player plugin of the browser, and the communication channel link is being overwritten.

You can easily verify my hypothesis by opening the 2 windows again, but now press the button in the LAST window first. Nothing will happen in that window, but the message will show up in the first window instead! Somehow, the last page's receiver is not created, because a receiver by that name already exists in the flash plugin's object store.

Can you confirm this, and more interestingly, does anyone have a workaround for this? Would it be possible to detect how many instances of an swf are running locally and use that for the connection name?

Edit: The observed behavior is not a bug, but intended behavior. However my problem still stands: how to have pages inside the same browser window communicate using a LocalConnection independently from the same pages in a different browser window on the same system.

StarShine
  • 1,940
  • 1
  • 27
  • 45

1 Answers1

2

The behavior mentioned in your question is a normal behavior and it's not a bug.

To understand why, think to your 2 opened windows as 2 windows which contain a client and a server each, and your two servers will listen to the same port PORT, and your two clients will both connect to that port in your local machine. So when you start the first window, the server will start listening for connections from clients on PORT, the second server will not start because the port PORT is already occupied, and so the first server will receive all clients connections.

For your second question about detecting how many instances of an swf are running locally, you can simply use SharedObject.

Hope that can help.

akmozo
  • 9,829
  • 3
  • 28
  • 44
  • Ah ok, it's by design. It's not very obvious how you'd use a SharedObject for counting the number of **live** instances (not just the total ever opened). I could generate and pass on a GUID (for example: http://snipplr.com/view/45247/as3-globally-unique-identifier-guid/) for all the pages within the same browser to use as the LocalConnection name, if that is what you are suggesting? – StarShine Sep 08 '15 at 07:40
  • @StarShine I don't know exactly what do you want to do with `LocalConnection`, but you can use `SharedObject` to count your swf instances and to be sure that when any of them create a new connection that will be unique : `swf1 : con1, swf2: con2, ..., swf_n: con_n` ... – akmozo Sep 08 '15 at 08:39
  • Hmm, that's not really what I need. (I think) Instead I want swf1 to talk to swf2 in browser window 1, while I want the same in browser window 2. Currently I have swf1 of window 1 talking to swf2 in window 2 (cross-window-messaging). Sorry if this is sounding a bit complicated :) – StarShine Sep 08 '15 at 09:29
  • 1
    @StarShine In that case ( you want just the swfs of the same window to communicate between them ), you can use [`ExternalInterface`](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html) to send the connection name ( generated after getting `SharedObject`, or using some hashing method, ... ) to the "client" of the same window which can then connect to it ... – akmozo Sep 08 '15 at 14:01
  • Thanks for replying! I'll look into your suggestion later this evening. By the way - and slightly off-topic - do you know a robust method or conversion tool to converting animation-rich flash swf's into html5? I looked into Swiffy and similar tools but none of them seem to do a decent enough job. I'd like to put flash behind me, but it looks like I'd have to rewrite everything from scratch. – StarShine Sep 08 '15 at 14:14
  • 1
    @StarShine About converting flash to html5, as you said, there is of course swiffy of google, I think also that Adobe Flash CC do that ... And between us, in such case, I prefer always write my own code because I like that ;) You can take a look on this [link](http://www.statsilk.com/blog/flash-versus-html5-wallaby-and-swiffy-conversion-tools-review) may be it can help you ... Good luck ! – akmozo Sep 08 '15 at 14:36
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/89076/discussion-between-starshine-and-akmozo). – StarShine Sep 08 '15 at 14:44