When, in ActionScript, an event is dispatched:
foo.addEventListener("some event", someHandler);
foo.dispatchEvent(new Event("some event"));
At what point are the event handlers executed?
I ask because I caught this at the end of an Adobe developer guide:
Notice that some properties are assigned to the [AsyncToken] after the call to the remote service is made. In a multi-threaded language, there would be a race condition where the result comes back before the token is assigned. This situation is not a problem in ActionScript because the remote call cannot be initiated until the currently executing code finishes.
But I could not find any information on what they meant by “currently executing code”.
Actionscript is a single threaded event driven language. Notice how there are no “main” methods in Actionscript. All code belongs in events, eg. initialization code tends to be placed in response to “creationComplete” events. Once the code in that event handler is run, the next event is executed. So if you did:
No other handler would be able to run because the currently executing code (the infinite loop) would never complete.
Note that Flash probably uses multiple threads internally, but that is abstracted from the developer.