Problem: You need to send stuff over sockets and have legacy code that must use Flash 8. Flash 8's XMLSocket doesn't come close to working for your purposes.
Solution: Make a Flash 9 container .swf that loads up the Flash 8 .swf. Have the flash 8 swf send strings to Flash 9 (which does have sockets) via a LocalConnection
Sub-problem: I coded it up and it doesn't work. Why not?
Answer: The docs on LocalConnection are badly written and/or omit required steps. You need a fully working example to show what all the necessary steps are.AS3to2.asAS3to2.swfflash8-snippet.asflash8bridgetest.swf
Pitfalls I encountered:
1) Most of the docs and tutorials out on the net omit the localconn.client = receivingObject;
step. Your callback function will never get called if you omit this. As is usual with code tutorials on the net, the stupid morans never actually compile and test the code they post to see if it works. But if you make this mistake, you at least get an error that says: "I can't call the callback".
2) I declared the LocalConnection a variable inside a function. As soon as the function exited, the garbage collector destroyed the variable. This causes recvString() to never get called. The LocalConnection variable needs to be a class variable or otherwise avoid going out of scope. This failure is completely silent - you won't get an error, it'll just not work. (Also for some reason fdb
won't step into any of the LocalConnection functions, so you can't debug it that way either. Extremely frustrating.)
3) I didn't realize that there were no command-line tools for < Flash 9. I spent a full day trying to figure out how to compile my flash8-snippet.as to a .swf with the Flex 2 SDK. Not happenin'. By the way, the flash8bridgetest.swf is a single frame .swf with a button, and the button's onclick just runs the two lines given. I had to get someone else to make it for me with commercial Flash authoring software. (Well, I suppose I could have tried FlashDevelop
Problems I expected but did not run into:
- I put in the localConn.allowDomain("localhost");
preemptively, and didn't have any problems with refused connections. Of course, both my .swfs were on the same machine. If you're trying to load the flash 8 swf from across the interwebs it will probably screw up.
- I'm using the free Flex 3.3 SDK, and thought there was a chance it might screw things up somehow. But nope, the above code works great for me under Flex 3.3.