Permalink
Browse files

Merge pull request #174 from yurydelendik/avm1-2

Fixes AVM1 onXxxxx event handler
  • Loading branch information...
2 parents 4dcf555 + d246e41 commit 99929933c8ba13ce86596c42e206a28ca92a3d64 @yurydelendik yurydelendik committed Mar 18, 2013
Showing with 14 additions and 10 deletions.
  1. +14 −10 src/avm1/classes.js
View
@@ -26,23 +26,27 @@ function proxyNativeMethod(methodName) {
function proxyEventHandler(eventName, argsConverter) {
var currentHandler = null;
- function handlerRunner() {
- if (currentHandler) {
- var args = argsConverter ? argsConverter(arguments) : null;
- return currentHandler.apply(this, args);
- }
- }
+ var handlerRunner = null;
return {
get: function() {
- return handlerRunner;
+ return currentHandler;
},
set: function(newHandler) {
+ if (currentHandler === newHandler) {
+ return;
+ }
if (currentHandler) {
- this.$nativeObject.removeEventListener(eventName, currentHandler);
+ this.$nativeObject.removeEventListener(eventName, handlerRunner);
}
currentHandler = newHandler;
- if (newHandler) {
- this.$nativeObject.addEventListener(eventName, newHandler);
+ if (currentHandler) {
+ handlerRunner = function handlerRunner() {
+ var args = argsConverter ? argsConverter(arguments) : null;
+ return currentHandler.apply(this, args);
+ }.bind(this);
+ this.$nativeObject.addEventListener(eventName, handlerRunner);
+ } else {
+ handlerRunner = null;
}
},
configurable: false,

0 comments on commit 9992993

Please sign in to comment.