[Pixlib] When to use custom event classes?
fluxs
fluxs at free.fr
Mon Oct 30 04:42:11 EST 2006
Hi,
Actually, when talking about pixlib events, it's easy to get confused
between the Event object 's "class" and its event type.
The event type is what subscribers subscribe to:
myBroadcaster.addEventListener( "placeOrderEvent", myListener);
This mean that the myListener.placeOrderEvent method will be called when
a "placeOrderEvent" is triggered.
This has nothing to do with the actual type (class) of the event object
that is sent.
For example you can define an OrderEvent class that will be used with
the placeOrderEvent, cancelOrderEvent etc.
Creating a custom event class is only necessary if you need to send your
custom data in an event : if you want to send an Order instance, you
will create an OrderEvent. If not, you might want to use one of the
predefined event classes.
For example if you just need to send an orderID when triggering a
cancelOrderEVENT, you may want to use the NumberEvent class.
Hope this helps,
fluxs
Marcelo de Moraes Serpa a écrit :
> Hello!
>
> I thought I knew about pixlib's event model. However, I'm a little
> confused.
>
> In ARP, I used MM's event dispatcher, so, when I wanted to dispatch a
> event, I would dispatch an event object. This object had a property
> with the name of the event to call.
>
> Pixlib goes one step further providing support for custom event
> classes. However, it's not clear on when I should create a custom
> event class (extending BasicEvent) instead of using the BasicEvent
> directly.
>
> Take Michael's (from deja-vue) pixlib MVC example. He has a OrderEvent
> class. However, the EventList class has 3 eventTypes registered.
> Xavier's sample does not use custom event classes at all.
>
> My conclusion is that, custom event classes are useful only when the
> event needs to carry a lot of data. Also, it's best to generalize it
> to the lower common denominator (OrderEvent, for example instead of
> getOrdersEvent, placeOrderEvent, cancelOrderEvent as all of these
> would use the same set of data) instead of creating a event class for
> each of the events, if possible, avoiding redundancy.. am I right?
>
> Cheers,
>
> Marcelo.
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Pixlib mailing list
>Pixlib at osflash.org
>http://osflash.org/mailman/listinfo/pixlib_osflash.org
>
>
More information about the Pixlib
mailing list