I usually have Events that match the "data" (for lack of a better word) they 
are related with.

eg: NewsEvent, UserEvent, etc..

Events then contain one or more static constants representing different event 
types.

eg: NewsEvent.GET_NEWS, NewsEvent.UPDATE_NEWS, UserEvent.LOGIN, 
UserEvent.LOGOUT, etc..

Here's one I'm actually using right now:
=============================================

public class NewsEvent extends MVCEvent {

 public static const GET_NEWS:String = "getNews";
 public static const UPDATE_NEWS:String = "updateNews";
 public static const ADD_NEWS:String = "addNews";
 public static const DELETE_NEWS:String = "deleteNews";

 public var data:NewsDTO;

 public function NewsEvent(type:String, dto:NewsDTO=null) {
  super(type);
  data = dto;
 }

 override public function clone():Event {
  return new NewsEvent(type, data);
 }

}

==============================================

The controller then maps the different event types to Commands:
// AppController:

 private function initCommands():void {
  addCommand(NewsEvent.GET_NEWS, GetNewsCommand);
  addCommand(NewsEvent.UPDATE_NEWS, UpdateNewsCommand);

  addCommand(NewsEvent.ADD_NEWS, AddNewsCommand);
  addCommand(NewsEvent.DELETE_NEWS, DeleteNewsCommand);
  // etc..
 }

==============================================

addCommand (not included) does an addEventListener and maps it to the command class for later execution (when the event is triggered).

That's about all the controller does really, listen for events, which are 
mapped to commands.
I do reduce the number of event classes by grouping them (NewsEvent has: get, 
add, update, delete),
instead of having an AddNewsEvent, GetNewsEvent, UpdateNewsEvent and so on.

Hope that helps.. do let us know if it doesn't :)

regards,
Muzak


----- Original Message ----- From: "Mattheis, Erik (MIN-WSW)" <[email protected]>
To: "Flash Coders List" <[email protected]>
Sent: Thursday, March 15, 2012 10:25 PM
Subject: [Flashcoders] Dispatching events from V to C


Say I have a "save" button that can exist in multiple views and can save multiple things. What's the best way to do this? Dispatch a different custom event from each type of button? Send one type of custom event with different parameters? I have a controller that listens for 28 different custom events. I'd like to make the controller class smaller.

_ _ _
Erik Mattheis | Weber Shandwick

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to