title: ActionScript event handler execution order
body: <p>I have been trying to understand the way ActionScript's events are implemented, but I'm stuck.</p>
  
  <p>I know that AS is single threaded, which means that only one event handler will be executing at a time, and also means that handlers will be executed in a deterministic order*.</p>
  
  <p>For example, consider the following code:</p>
  
  <pre><code>1: var x = {executed: false};
  2: foo.addEventListener("execute", function(){ x.executed = true; });
  3: foo.dispatchEvent(new Event("execute"));
  4: assert(x.executed);
  </code></pre>
  
  <p>If ActionScript was multi-threaded, it would be possible that the assertion on line 4 could fail sometimes and succeed others.</p>
  
  <p>But since AS is not multi-threaded, it stands to reason that the assertion will either <em>always</em> fail² or <em>always</em> succeed³.  Or, in other words, events will be handled in a deterministic way.</p>
  
  <blockquote>
    <p>So, is this assumption (that events hare handled deterministically) correct? Does Adobe provide any definitive documentation on the matter?</p>
  </blockquote>
  
  <p>Note: I am <em>only</em> concerned here with events dispatched by <code>dispatchEvent</code> – I realize that "externally dispatched" events (network traffic, user input, timers ticking, etc) behave differently.</p>
  
  <hr>
  
  <p>*: with the exception, of course, for events triggered by nondeterministic things like user input or network traffic.<br>
  ²: it would always fail if, for example, if the event handling algorithm was: "push new events onto a stack, then continuously pop the top event off the stack, execute it until it terminates, then go on to the next event".<br>
  ³: it would always succeed if events dispatched by <code>dispatchEvent</code> were handled as soon as they were dispatched.</p>