//declare the signal private var _sigSomthingHappened= new Signal();
// optional Data type for explicit coding incase you // want to pass along a specific argument with the signal when its dispatched // you can use any data type Strings, ints, numbers, value objects etc. private var _sigSomthingHappened= new Signal(String);
//DISPATCH _sigSomthingHappened.dispatch();
//DISPATCH WITH ARGUMENT _sigSomethingHappened.dispatch("playerJumped");
//LISTEN TO THE EVENT FROM ANOTHER CLASS signalLocation.sigSomethingHappened.add(somethingHappened) or //if your only want to listen to the event once you can do this signalLocation.sigSomthingHappened.addOnce(somethingHappened)
//You can listen to a combination of both simultaneously
//EVENT HANDLER private function somethingHappened(action:String = null):void { trace("the player has:"+action) }
//REMOVE LISTENERS signalLocation.sigSomethingHappened.remove(somthingHappened) //or if you have multiple listeners on a signal and want to remove them all at once signalLocation.sigSomethingHappened.removeAll();
Delux Signals:
Delux signals allow you to trace the event location and signal which is behaviour we are white used to with native events.
//pass in the location the signal is coming from private var _sigSomthingHappened= new DeluxSignal(this); //when dispatching a new GenericEvent must be passed in _sigSomthingHappened.dispatch(new GenericEvent());
//Listener signalLocation.sigSomethingHappened.add(somthingHappened); private function somethingHappened(e:GenericEvent):void { trace(e.target); trace(e.signal); }
Leave A Comment