Listener VS. EventListener

Hi Guys

I was conducting some experioments on the Combo box component.

So I was using addEventListener(“change”,myListener) and it was working fine, then I thought of trying addListener instead, but then it didn’t work. This lead me to google search what addListener does.

Anyway, I saw some stuff that made me conclude that there is a “listener” and there is an “event” and there’s a difference between them. The Key object as 2 listeners: onKeyUp and onKeyDown , but none of the components have listeners, they just have events.

So I wanted to know why, and whats the difference between a listener and an event, and the difference between addListener and addEventListener.

Thanks dudes!!!

The practical difference is that when you use addListener() you get all events broadcast to your listener-object. addEventListener on the other hand makes your listener recieve only the event you have subscribed for. However you can use multiple addEventListener calls to listen for different events.

I think the difference is bigger behind the scenes. When creating a class/component that uses addListener or addEventListener. Don’t rember what other than when using addListener you do a single function call and when using addEventListener you use a method of the mx.events.EventDispatcher class.

/Mirandir

But how come you can’t use addListener with any of the components? I tried it and it doesn’t work !! And in the addListener tutorial, they relate only to the Key component

It really depends on the implementation of component…

addListener and addEventListener both functions do not have to be together… they are different functions being exposed by the respective classes (components)

So how would you know which one to use? As I tried to use addListener, but it didn’t work. Im trying to grasp this thing

Components all use eventListener only. While the “standard” classes that supports listeners usuall has the general addListener functionality instead. Check the reference manual for when to use addListener with the standard classes.

/Mirandir

Well totally depends on how some particular Component or Class is built…

Say if I develop a new component myself I may implement both the functions or may be one of them only…

Components use addEventListener because they implement the EventDispatcher Class.
this can mainly be found in all component of the v2 framework.

thus the component will have a declaration of addEventListener within it. That is why you can call it and register an object to it.

all non components such as Key class do not implement EventDispatcher Class. Rather they can simply manage with AsBroadcaster class instead.

AsBroadcaster implements addListener…
EventDispatcherimplements addEventListener…