You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Mark Line <ma...@gmail.com> on 2015/03/04 22:30:51 UTC

Event order processing

Hi,

I was wondering if someone could confirm something for me about event
processing. I know if you two events are dispatched one after another, the
second event will be dispatched only after all handlers of the first event
are executed and the dispatchEvent method is returned.

However does anyone know what would happen if during the event processing
of the first event it dispatched another event. Would the new event be
processed before any of the other event listeners (think event life cycle
if it was bubbling).

A very basic example:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
   xmlns:s="library://ns.adobe.com/flex/spark"
   xmlns:mx="library://ns.adobe.com/flex/mx"
   creationComplete="init(event)">

<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function button1_clickHandler(event:MouseEvent):void
{
trace("button1_clickHandler");
this.dispatchEvent(new FlexEvent(FlexEvent.CHANGE_END));
}
 protected function eventOneHandler(event:Event):void
{
trace("eventOneHandler");
this.dispatchEvent(new FlexEvent(FlexEvent.CHANGE_START));
eventThreeHandler(new Event("blah"));
}
 protected function eventTwoHandler(event:Event):void
{
trace("eventTwoHandler");
}
 protected function eventThreeHandler(event:Event):void
{
trace("eventThreeHandler");
}
 protected function init(event:FlexEvent):void
{
this.addEventListener(FlexEvent.CHANGE_END, eventOneHandler);
this.addEventListener(FlexEvent.CHANGE_START, eventTwoHandler);
}
 ]]>
</fx:Script>

<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<s:Button label="Click me"
  click="button1_clickHandler(event)"/>
</s:Application>


Eg would Flex make sure the event handlers registered for my
this.addEventListener(FlexEvent.CHANGE_START,
eventTwoHandler) before return flow to the button1_clickHandler.

Re: Event order processing

Posted by Mark Line <ma...@gmail.com>.
Thanks that makes sense
On 4 Mar 2015 21:43, "Ronny Shibley" <rs...@codefish.com> wrote:

> Think of it like calling a method. There are no timers and no multiple
> threads. If an event is dispatched in the middle it bubbles up and then
> original event  continues bubbling up.
>
> Ronny Shibley
>
> > On Mar 4, 2015, at 11:30 PM, Mark Line <ma...@gmail.com> wrote:
> >
> > Hi,
> >
> > I was wondering if someone could confirm something for me about event
> > processing. I know if you two events are dispatched one after another,
> the
> > second event will be dispatched only after all handlers of the first
> event
> > are executed and the dispatchEvent method is returned.
> >
> > However does anyone know what would happen if during the event processing
> > of the first event it dispatched another event. Would the new event be
> > processed before any of the other event listeners (think event life cycle
> > if it was bubbling).
> >
> > A very basic example:
> >
> > <?xml version="1.0" encoding="utf-8"?>
> > <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
> >   xmlns:s="library://ns.adobe.com/flex/spark"
> >   xmlns:mx="library://ns.adobe.com/flex/mx"
> >   creationComplete="init(event)">
> >
> > <fx:Script>
> > <![CDATA[
> > import mx.events.FlexEvent;
> > protected function button1_clickHandler(event:MouseEvent):void
> > {
> > trace("button1_clickHandler");
> > this.dispatchEvent(new FlexEvent(FlexEvent.CHANGE_END));
> > }
> > protected function eventOneHandler(event:Event):void
> > {
> > trace("eventOneHandler");
> > this.dispatchEvent(new FlexEvent(FlexEvent.CHANGE_START));
> > eventThreeHandler(new Event("blah"));
> > }
> > protected function eventTwoHandler(event:Event):void
> > {
> > trace("eventTwoHandler");
> > }
> > protected function eventThreeHandler(event:Event):void
> > {
> > trace("eventThreeHandler");
> > }
> > protected function init(event:FlexEvent):void
> > {
> > this.addEventListener(FlexEvent.CHANGE_END, eventOneHandler);
> > this.addEventListener(FlexEvent.CHANGE_START, eventTwoHandler);
> > }
> > ]]>
> > </fx:Script>
> >
> > <fx:Declarations>
> > <!-- Place non-visual elements (e.g., services, value objects) here -->
> > </fx:Declarations>
> >
> > <s:Button label="Click me"
> >  click="button1_clickHandler(event)"/>
> > </s:Application>
> >
> >
> > Eg would Flex make sure the event handlers registered for my
> > this.addEventListener(FlexEvent.CHANGE_START,
> > eventTwoHandler) before return flow to the button1_clickHandler.
>

Re: Event order processing

Posted by Ronny Shibley <rs...@codefish.com>.
Think of it like calling a method. There are no timers and no multiple threads. If an event is dispatched in the middle it bubbles up and then original event  continues bubbling up.

Ronny Shibley

> On Mar 4, 2015, at 11:30 PM, Mark Line <ma...@gmail.com> wrote:
> 
> Hi,
> 
> I was wondering if someone could confirm something for me about event
> processing. I know if you two events are dispatched one after another, the
> second event will be dispatched only after all handlers of the first event
> are executed and the dispatchEvent method is returned.
> 
> However does anyone know what would happen if during the event processing
> of the first event it dispatched another event. Would the new event be
> processed before any of the other event listeners (think event life cycle
> if it was bubbling).
> 
> A very basic example:
> 
> <?xml version="1.0" encoding="utf-8"?>
> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
>   xmlns:s="library://ns.adobe.com/flex/spark"
>   xmlns:mx="library://ns.adobe.com/flex/mx"
>   creationComplete="init(event)">
> 
> <fx:Script>
> <![CDATA[
> import mx.events.FlexEvent;
> protected function button1_clickHandler(event:MouseEvent):void
> {
> trace("button1_clickHandler");
> this.dispatchEvent(new FlexEvent(FlexEvent.CHANGE_END));
> }
> protected function eventOneHandler(event:Event):void
> {
> trace("eventOneHandler");
> this.dispatchEvent(new FlexEvent(FlexEvent.CHANGE_START));
> eventThreeHandler(new Event("blah"));
> }
> protected function eventTwoHandler(event:Event):void
> {
> trace("eventTwoHandler");
> }
> protected function eventThreeHandler(event:Event):void
> {
> trace("eventThreeHandler");
> }
> protected function init(event:FlexEvent):void
> {
> this.addEventListener(FlexEvent.CHANGE_END, eventOneHandler);
> this.addEventListener(FlexEvent.CHANGE_START, eventTwoHandler);
> }
> ]]>
> </fx:Script>
> 
> <fx:Declarations>
> <!-- Place non-visual elements (e.g., services, value objects) here -->
> </fx:Declarations>
> 
> <s:Button label="Click me"
>  click="button1_clickHandler(event)"/>
> </s:Application>
> 
> 
> Eg would Flex make sure the event handlers registered for my
> this.addEventListener(FlexEvent.CHANGE_START,
> eventTwoHandler) before return flow to the button1_clickHandler.

Re: Event order processing

Posted by Alex Harui <ah...@adobe.com>.

On 3/4/15, 2:22 PM, "Jeffry Houser" <je...@dot-com-it.com> wrote:

>On 3/4/2015 4:30 PM, Mark Line wrote:
>> Hi,
>>
>> I was wondering if someone could confirm something for me about event
>> processing. I know if you two events are dispatched one after another,
>>the
>> second event will be dispatched only after all handlers of the first
>>event
>> are executed and the dispatchEvent method is returned.
>
>  I did not think this was true.  Isn't Event dispatching a
>multi-threaded process?

I don’t know if there are guaranteed behaviors when ActionScript Workers
are involved, but without workers, there is only one ActionScript thread
running, and events are serviced as others have described.
The Player may have received events asynchronously or in other
non-ActionScript VM threads, but I’m pretty sure the handlers are all
executed by the one ActionScript thread which means that all handlers and
handlers for events fired in the handling of the first event must finish
before the second event’s handlers begin to run.  Handlers can be skipped,
of course, via stopPropagation and stopImmediatePropagation.

>
>> Eg would Flex make sure the event handlers registered for my
>> this.addEventListener(FlexEvent.CHANGE_START,
>> eventTwoHandler) before return flow to the button1_clickHandler.
>
>  No; Flex would not because event handlers would be triggered in
>parallel.  There is no way to conclusively determine when an event
>handler will fire in relation to other events or event handlers.
>

Is there a specific scenario you are thinking of where parallel event
handlers might occur?

-Alex


Re: Event order processing

Posted by Jeffry Houser <je...@dot-com-it.com>.
On 3/4/2015 4:30 PM, Mark Line wrote:
> Hi,
>
> I was wondering if someone could confirm something for me about event
> processing. I know if you two events are dispatched one after another, the
> second event will be dispatched only after all handlers of the first event
> are executed and the dispatchEvent method is returned.

  I did not think this was true.  Isn't Event dispatching a 
multi-threaded process?

> Eg would Flex make sure the event handlers registered for my
> this.addEventListener(FlexEvent.CHANGE_START,
> eventTwoHandler) before return flow to the button1_clickHandler.

  No; Flex would not because event handlers would be triggered in 
parallel.  There is no way to conclusively determine when an event 
handler will fire in relation to other events or event handlers.


-- 
Jeffry Houser
Technical Entrepreneur
http://www.jeffryhouser.com
203-379-0773


Re: Event order processing

Posted by Luis67 <ch...@gmail.com>.
Well I agree on your points. You know, we also had back to back three events.
Two were at pour place and then  wedding reception <https://eventup.com/>  
at our in laws place. But thanks to our planer who managed everything
nicely.




--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Event-order-processing-tp9741p9751.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.