You do not have to make a new signal class for Command maps, its just good practice. You could just give the "dataType" class a type property - and do a switch
on that. But that would be messy for commands. But note, Commands are basically for triggering application wide actions.
Not all signals trigger application wide actions.
For instance, if you are responding to a heap of events from a single View
. I suggest making a Signal
class for related "view events" (e.g. MyButtonSignal
for MyButtonView
) and give it a type property.
A typical signal of mine will look like:
package {
public class MyButtonSignal extends Signal {
public static const CLICK:String = 'myButtonClick';
public static const OVER:String = 'myButtonOver';
public function MyButtonSignal() {
super(String, Object);
}
}
}
Dispatch like so
myButtonSignal.dispatch(MyButtonSignal.CLICK, {name:'exit'});
Listen as normal:
myButtonSignal.add(doMyButtonSignal);
Handle signal like so:
protected function doMyButtonSignal(type:String, params:Object):void {
switch(type) {
case MyButtonSignal.CLICK: trace('click', params.name);
break;
case MyButtonSignal.OVER: trace('OVER', params.name);
break;
}
}
Occasionally its useful to give the data
variable its own data class.
So everytime you realise "Aw shit, I need to react to another event", you simple go to the Signal
and add a new static const to represent the event. Much like you (probably?) did when using Event
objects.