I have had to deal with asynchronous code in ActionScript and also in C# when dealing with browser control. Well, at least the way I was doing it, it was very cumbersome, resulting in spaghetti code. Meanwhile, it seemed that in many places the complexity added by the asynchronous aspect of the code was not in any sense “intrinsic”. E.g. when an AS3 program loads a file from disk, why should it be asynchronous? In C#/Java programs this is done synchronously and it works fine. In some cases with browser control similarly the asynchronous aspect seemed pointless complexity.
Well, so has there been work done on automatically translating programs written using “synchronous” style into equivalent asynchronous ones? E.g. if I want to say “str = LoadFile(path); //now use variable str in 10 more lines of code including some other calls to obligately asynchronous methods” did anybody try making a translator that would take this natural code and convert it into the asynchronous spaghetti version that can be executed?
I don’t know offhand of any projects designed for this specific pre-compilation purpose. While the notion that the event handler model leads to spaghetti code is certainly debatable, I can understand that you’d want some simple file operations to be synchronous and blocking at times. Is your ActionScript project designed to be only run within a web browser window? If you’re not tied down to a browser (for example, if you’re designing an app that is meant to be distributed), you can look into Adobe AIR. AIR is basically a wider sandboxed environment for Flash/Flex/ActionScript applications to run in, and allows installing programs through the AIR installer as if they were standalone programs. It adds a handful of extra functionality like synchronous file I/O and SQLite support, to name a few.