views:

34

answers:

2

I found an interesting questions regarding the events in action script: is the event buffered and ordered?

Ie) In a swfloader example, I setup a timer(1 sec) to run a function, in the function I setup a listener to event INIT of the loaded swf. It depends on the network condition that whether the timer handler or the INIT event will be first executed. Imagine a case that the INIT event fired first but the handler to handle the INIT event be setup later, will the handler be invoked?

Another question, if the loaded swf fired several events very fast, will the events be kept ordered as the fire sequence?

+1  A: 

First Question: No, if INIT event is fired first and there is no handler for that Event then that event will be lost. So the best way is to setup all the listeners first then start any loading operation.
Second Question: Yes, all the events fired will be handled in the same order as they're fired.

bhups
A: 

i just wanted to add to that you can change the order in the optional params by default first in is the first served but if you change you priorities around that can change

obj.addEventListener(type,listener,useCapture,priority,useWeakRefrence);

the higher the number is the higher it is in priority. so if i would add these events:

obj.addEventListener(type,listener1,useCapture,1,useWeakRefrence); obj.addEventListener(type,listener2,useCapture,2,useWeakRefrence);

the second event would happen before the first one. p.s after you create the event there is no way to change the order without removing the event and adding it back in.

--

EventController - AS3 Event management made easy.

http://fla.as/ec/

Ben Fhala