I’m just curious how a lot of you handle custom events.
My custom event/s that I will be creating pertain to creating and displaying views. I want to have two separate events dispatched, one to create the view and then one to display the view.
I see three ways of doing this:
-
Create a single ViewEvent class with two constants CREATE_VIEW and DISPLAY_VIEW. The problem with a single event class is that I would like if possible to use strongly typed parameters. WHen using CREATE_VIEW though, I want to pass an ID that corresponds to the view to create and when I dispatch DISPLAY_VIEW I’d like to pass the view object to display. So I would need to either use two optional parameters, one for viewId of type int and one for view of type DisplayObject and then test for which one exists which I don’t like.
-
Same as number 1 except use a single generic parameter and check for it’s type to see what the event’s payload is which I don’t like generic parameters either.
-
Create two separate event classes, a CreateViewEvent and a DisplayViewEvent. This would allow me to use the proper typed parameters, but it seems a little weird since both event actions are so closely related that I feel they should be within the same event class.
So the question is… in general what are everyone’s views on handling a situation like this?