NResponder's features

To talk about the features of NResponder I want to give a little comparison.
In the following table you can see the native Envent Engine (or API) compared to the features of NResponder.
Feature Event API
(Adobe® Flash®)
NResponder
(Diney Bomfim)
Use without instance No Yes
Use with instance Yes Yes
Specify number of dispatch arguments No Yes
Dynamic dispatch arguments No Yes
Change dispatch arguments in Run-Time No Yes
Remove all No Yes
Specify a delay time No Yes
Set the number of replies No Yes
Ordinate Yes Yes
Can associate with a target Yes Yes
Can pause without remove No Yes
Can stop propagation Yes Yes
Change attributes in Run-Time No Yes
Garbage Collect only weak references Yes

I will focus on the most important and more usable features:

Static and instantiated mode
With NResponder you can choose the best to way to work. Use it as a static class, without create any constant or variable, or use it as instance, a more object oriented approach.
A important thing to say is that the instantiated mode offers to you more control over the event, like pause it without remove.

Custom number of arguments and changes
This is really one of my favorite features. As you know, in the native Event Engine of Flash the dispatcher MUST and NEED to inform ONE, and just one, Event instance. And the call back functions need to expect that kind of event.
So, for example, what you have is:

eventDispatcherInstance.addEventListener("aCustomEvent", callBackFunction);
eventDispatcherInstance.dispatchEvent(new MyCustomEvent("aCustomEvent"));
...
private function callBackFunction(event:MyCustomEvent):void
{
...
}


This is boring!!!
If you want to pass some kind of data to your callBackFunction() you need to put new variables to your MyCustomEvent class!
Just forget it!!!
With NResponder you can pass how many parameters you want and can have a call back function like this:

private function callBackFunction(aNumber:Number, aString:String, customObject:ACustomObject):void
{
...
}


This give to you so much more flexibility to work!
Because you can make your call back functions more readable and more reusable.

Number of replies
This is one of my favorite too.
With this feature you can simple set the number of times that a specific event (or Action, in NResponder language) will happen!
How many you want, just 5, or until 21, anything!
One very common and useful usage of this is for view classes.
As you know, when you start a view class and it is not on the stage yet, its property of "stage" is null. So a technique widely accepted among developers is the use of:

public function Main()
{
    if (this.stage)
    {
        init(null);
    }
    else
    {
        this.addEventListener(Event.ADDED_TO_STAGE, init);
    }
}

public function init()
{
    if (this.hasEventListener(Event.ADDED_TO_STAGE))
    {
        this.removeEventListener(Event.ADDED_TO_STAGE, init);
    }
}


You need to add and remove, make checks to hasEventListeners, to use this routine just ONCE!
Is boring!!!
With NResponder all that you need is set the number of replies, in this case, to 1 and stay focus on your code!
Because NResponder will be responsible to later clean up the mess, delete what it need to delete, frees the memory and go on.

Delay time
This can be very helpful for some situations.
The delay time specify the time, in seconds, that will be the minimum to wait between two consecutive dispatches.
For example, you have a button in your game that the user need to press continuously. But you want a little interval of time between two clicks, like 0.5 secs. With NResponder all that you need is set one property and everything will be controlled by the NResponder engine.

Combined removes
With the native Event Engine if you set a lot of listeners and after need to remove that listeners, you need to remove one by one.
With NResponder you can make combined removes, like remove all listeners of a target, remove all listeners of a specific call back function, remove all listeners of a specif type (Action), like Mouse.CLICK, or even make combination like remove all listeners of a specific target with a specific call back function.
Don't worry if this don't make sense to you now, when I show the examples, everything will becomes clearer.

OK, these are the most important features of NResponder.
I will not talk about features that have a correlated in native Event Engine, like order or stop propagations. Because I suppose that you already know from EventDispatcher.

One more thing...
Something that you may think now is: "OK, you talk about mouse events, keyboard, touches... and said that I can say Goog Bye to native Event Engine... but are not mouse, keyboard and touches native events?".
Yeh!
You are right!
With NResponder you don't need any instance of EventDispatcher in your application, you don't need to use the processing core of native Event Engine.
But if you want, NResponder give you a way to use the native system under the NResponder engine system.
Obviously to work with mouse envets, keyboard, touches, etc, NResponder need to use a little portion of the native Event Engine, because is the only way to catch this kind of event in Flash.
But again, NResponder can do this so much better than using the native EventDispatcher process.