Best practice for dispatching view events to a mediator

kamcknig's Avatar


09 Dec, 2011 09:25 PM

What is the best practice for getting view events out to the system?

In my mind as I think about it, views should not necessarily have access to the concrete custom events used in the system. The view should probably dispatch a generic flash event which the mediator catches and the mediator should then convert the data and encapsulate it into an application specific event.

Does that sound right?

If so, what is the best practice for doing things, let's say on a mouse click in a view. If the mediator has a view, and that view has many child views, should the mediator add a listener for a click on the view and then in the handler check what type of view was clicked to find out what type of event? I know there shouldn't be a lot of logic in a mediator so I don't want some big long function with a switch or a bunch of if/else statements. So is this ok though? And the only thing to do if it gets too big is to split the mediator into multiple mediators for the child views? Or is there another best practice for handling this kind of thing?

I do know about the eventMap.mapListener for listening for events on child views, and that would just break out the switches or if/else statements to separate functions, but is still technically doing the same thing in that case.


  1. 1 Posted by Stray on 09 Dec, 2011 10:09 PM

    Stray's Avatar

    I definitely wouldn't go with a switch in the handler.

    Better options (in no particular order)

    1) Expose child view parts with getters. Then eventMap.mapListener(view.someButton, ...)

    (Downside is that this also exposes that view part for double-dot access that breaks encapsulation, eg view.someButton.x = 20;

    2) Dispatch custom events that are custom to the view not the application domain. So 'LoginFormEvent.SUBMIT_CLICKED' etc.

    3) Give the view AS3 Signals - eg submit / cancel etc.

    Personally I think this is what signals do best - but if you're not familiar with them then I'd go with 2 or 1 in preference to putting that logic in the handler,


  2. 2 Posted by kamcknig on 09 Dec, 2011 10:12 PM

    kamcknig's Avatar

    OK great thanks!

    I have started using signals but not in this application so I'll prbably not use that for now, but I do like them and will try and use them more in the future!


  3. kamcknig closed this discussion on 09 Dec, 2011 10:12 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac