EventDispatcher in Flex is single threaded
This may be a very little futile detail and may be commonly known. But being a flex novice, it bothered me for a while when I was trying to find out when events are dispatched, in which order the listeners get called. It specially becomes important when you are overriding a framework class and want to override the default event listener behavior.
Event dispatcher is single threaded and all the listers for a particular event in LIFO order they were added, in other words last one being called first and next after execution of first finishes and so on.
Example
Class A{
public function init() {
foo.addEventListner(event.Type, callBack);
}public function callBack(event:Event):void{
//implementation…
}}
Class B extends A{
public function init() {
foo.addEventListner(event.Type, localCallBack);
}public function localCallBack(event:Event):void{
//implementation…
}
}
In this example, localCallBack will be invoked before callBack() and if you want to stop the execution of super listener, you can set a property from the subclass listner callback on the event and check that property in the super callBack method.
This is the same mechanism framework uses in variety of events in Tree, Datagrid etc (event.preventDefault()) and is guaranteed to work because of the event dispatcher being single threaded.
