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.
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.
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)
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.