diff --git a/lib/OpenLayers/Events.js b/lib/OpenLayers/Events.js index fbdf9ca83a..69d12fe6f0 100644 --- a/lib/OpenLayers/Events.js +++ b/lib/OpenLayers/Events.js @@ -158,15 +158,22 @@ OpenLayers.Events.prototype = { // execute all callbacks registered for specified type var listeners = this.listeners[type]; - for (var i = 0; i < listeners.length; i++) { - var callback = listeners[i]; - - // use the 'call' method to bind the context to callback.obj - var continueChain = callback.func.call(callback.obj, evt); - - if ((continueChain != null) && (continueChain == false)) { - // if callback returns false, execute no more callbacks. - break; + if (listeners != null) { + + for (var i = 0; i < listeners.length; i++) { + var callback = listeners[i]; + var continueChain; + if (callback.obj != null) { + // use the 'call' method to bind the context to callback.obj + continueChain = callback.func.call(callback.obj, evt); + } else { + continueChain = callback.func(evt); + } + + if ((continueChain != null) && (continueChain == false)) { + // if callback returns false, execute no more callbacks. + break; + } } } }, diff --git a/tests/test_Events.html b/tests/test_Events.html index 862712c4f3..4e807a1370 100644 --- a/tests/test_Events.html +++ b/tests/test_Events.html @@ -4,6 +4,7 @@