I was using dispatchEvent and was worried that the next line of code would be run before the recipients of the dispatch had executed their code. Based on the trace that I got the response is immediate. This lead me to start thinking...
Does dispatching an event essentially mean that the next thing on the callstack is the execution of the associated method on the event handlers?
As I was Googleing it the answer started to make more sense Since the dispatcher is really grabbing an array of eventListeners and calling all of their methods this would happen before the next line of code is executed. for a split second I was worried that it might be an asynchronous process- you know like waiting or "onResult" to be called from a Remoting call.
So just to state the obvious so I can clarify it to the 6 ActionScript coders who have not read Moock's Essential ActionScript 2.0 or Elst's Object-Oriented ActionScript for Flash 8 here we go:
When you call the static EventDispatcher.initialize(myClass) on a class it is passed through the following function in the "EventDispatcher Machine" - err quick check- if it's illegal to post this code someone drom me a comment- preferably someone non-Adobe law affiliated.
-Where was I?
it adds these methods to the given class.
The addEventListener(event, handler) method actually takes the handler object/function and pushes it to the "queue" for the stated event.
The one that I'm particularly interested in is the dispatchEvent(eventObj) method. Inside it you have the following lines:
Line one essentially calls a method with the eventObject's name+Handler within your class
(e.g.; if your event object was {type:"burp", volume:10, sourFluid:true} it would call burpHandler internally before event calling the handlers that you requested be handled)
When the EventDispatcher is done handling it's own Handler business it passes the eventObject to the dispatchQue. Our main concern is line 30 the o.apply(queueObj, [eventObj]); If you are not familiar with this use of apply check out Foundation ActionScript for Flash mx 2004. Sham breaks it down pretty clearly. It basically takes the object o and runs it's function-queue(who in the hell decided how to spell that word )- passing it the parameters eventObj
It actually does this for each item "i" in the que.
Now to return to my main point that lead me down this long winded exploration.
If I have the following:
it is effectively the same as having this
so unlike an asynchronous call where you call and wait for results- this happens immediately and predictably. the methods on the listeners are placed in the callstack and executed ahead of the "blowItOut()" method.
I know this was longwinded but honsetly - this was more for me to hammer it into my brain than for you to wonder why i didn't add a property "flavor" on my burp event. I just figured that I would put it out there in case anyone else had thought about it. If any part of this explanation is not clear or just plain wrong someone set me straight or clarify. if someone knows how to spellcheck with Wordpress that's welcome information as well.
Discussion
No comments for “EventDispatcher is fast and NOT an Asynchronous process–duh!!”
Post a comment