You do not need to create a new class of signals for command cards, this is just good practice. You can simply set the "dataType" class to the type property and make a switch . But that would be dirty for the teams. But note: the commands are mainly designed to trigger a wide-action application.
Not all signals trigger large-scale application actions.
For example, if you are responding to a bunch of events from one View . I suggest creating a Signal class for related view events (e.g. MyButtonSignal for MyButtonView ) and assigning a type property to it.
A typical signal would look like this:
package { public class MyButtonSignal extends Signal { public static const CLICK:String = 'myButtonClick'; public static const OVER:String = 'myButtonOver'; public function MyButtonSignal() { super(String, Object); } } }
Shipping as such
myButtonSignal.dispatch(MyButtonSignal.CLICK, {name:'exit'});
Listen as usual:
myButtonSignal.add(doMyButtonSignal);
Handle this way:
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; } }
It is sometimes useful to use the data variable as your own data class.
So, every time you understand โAw shit, I need to respond to another eventโ, you just go to Signal and add a new static const to represent the event. Much like you (probably?) When using Event objects.
source share