possible addEventListener bugs?

Has anyone encountered addEventListener weirdness like this?

http://www.youtube.com/watch?v=PnDzm5fcYz8

-addEventListener registers the same event multiple times
-on event dispatch if the handler is removed and readded you get an infinite loop
-in one case addEventListener doesn’t add the handler of an object

You might ask why would you do the first two. Well normally you wouldn’t, but I came across the third in a real world example and found the first two which says to me that addEventListener might need some looking at.

I created my own versions of the event dispatcher functions. If anyone needs them give a shout and I’ll paste them. [import]uid: 27183 topic_id: 13096 reply_id: 313096[/import]

Here’s a video showing some more weirdness a before and after: http://www.youtube.com/watch?v=SM1uU0llaIk

The error shown is related to this thread: http://developer.anscamobile.com/forum/2011/08/01/really-weird-error
[import]uid: 27183 topic_id: 13096 reply_id: 48264[/import]

I found out as a result of implementing my own event dispatching functions that collision events aren’t dispatched with dispatchEvent! I get ‘sprite’, ‘touch’, ‘drag’ events, but ‘collision’ is not being dispatched to my objects with dispatchEvent. :frowning:

It’s a long shot that any of the Ansca guys will reply to this, but how do I capture the ‘collision’ events and send them through my custom dispatchEvent function?

Thanks. [import]uid: 27183 topic_id: 13096 reply_id: 48528[/import]

I figured out a work around. if you attach a collision event listener with the original addEventListener then replace the event functions the collision events will fire!

So I just attach an empty function like:

obj:addEventListener(‘collision’, function() end)

then I can replace the functions.
obj.addEventListener = myAddEventListener
obj.dispatchEvent = myDispatchEvent
obj.removeEventListener = myRemoveListener

[import]uid: 27183 topic_id: 13096 reply_id: 48538[/import]

Hey Don, you mentioned:
I created my own versions of the event dispatcher functions. If anyone needs them give a shout and I’ll paste them.

I’m interested in looking at the custom functions you made. If it’s not too much trouble, it would be great if you’d post them here (or wherever is convenient to you). Thanks! [import]uid: 67217 topic_id: 13096 reply_id: 60249[/import]

Hi Naomi,

The custom functions are actually part of the Spriteloq API. Look inside of loq_util and search for loq_listeners. You can call loq_listeners on a display object to attach the custom event api.

I’ve been using for some time now without issue. [import]uid: 27183 topic_id: 13096 reply_id: 60250[/import]

Some minimal documentation here: http://www.loqheart.com/spriteloq/apidocs/files/loq_util-lua.html#loq_listeners

[import]uid: 27183 topic_id: 13096 reply_id: 60252[/import]

Hey Don, I just looked at the Youtube video from the link provided above. It mentions loq_listener, which is included with loq_util API – and that means, I already have it! Thanks! [import]uid: 67217 topic_id: 13096 reply_id: 60253[/import]

Thanks, Don! [import]uid: 67217 topic_id: 13096 reply_id: 60254[/import]