views:

87

answers:

2

I've a little problem, I don't really understand if I can use addEventListener more than one time on the same object (and same callback function) if this case can I have a problem of overflow, or simple flex is so smart to not add again in the same stack same function

for examples:

var t:CServiceObj = _rModel.userGetBoardJoined(); 
t.addEventListener(EDataService.DATA_AVAILABLE,onDataOk);
t.addEventListener(EDataService.DATA_AVAILABLE,onDataOk);
t.addEventListener(EDataService.DATA_AVAILABLE,onDataOk);
+1  A: 

Hi,

As you say, Flex is "smart" and even if you subscribe to an event more than once on the same instance, then the handler will be called Just once (no matter how many addEventListener you pass).

Adrian Pirvulescu
Can you post a link to docs that supports this? And btw, this is unless you used different values for `useCapture` http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/EventDispatcher.html#addEventListener%28%29
Amarghosh
+1  A: 

I tried a quick test on Button and it doesn't matter if the addEventListener is added multiple times to the same function -- it gets dispatched once.

However, you could set up something like this

t.addEventListener(EDataService.DATA_AVAILABLE,onDataOk);
t.addEventListener(EDataService.DATA_AVAILABLE,onDataOk2);

where onDataOk2 calls onDataOk with the event parameter.

Interesting Note A different test, I added a click handler in the mxml tag, and a click handler in the AS, both pointed to the same function. When the button was clicked, both handlers dispatched, so Flex did something behind the scenes to accomodate this functionality.

adamcodes