Gabriel Dehan
Gabriel Dehan

Reputation: 1107

Titanium Android native module - addEventListener not found

I am on this project ( an horrible one with a full procedural ultra-smelly code an other society produced before handing it over to us ).

We have a native Android module, a Carousel. Each element of the carousel can be clicked and thus trigger the corresponding action.

Logically enough, we simply added an addEventListener on the instanciated module in Titanium and it is fully working the first time we launch the application. But once we quit and restart the application, we get an error Object [Object Carousel] has no method addEventListener.

I don't understand why. If it is working the first time it should work the second time. Is there some sort of memoization that is going wrong ? Or a failed garbage collection ? Here is the code we have used in Titanium to handle this logic :

function some_func() {
  CF_container = null;
  var my_module = require('com.xxxx.carousel');
  CF_container = my_module.createView();
  CF_container.addEventListener('IZ_itemClicked', function(data) {
    evts_CF_click(data.id);
  });
  return CF_container;
}

Upvotes: 0

Views: 591

Answers (1)

Jeff Bonnes
Jeff Bonnes

Reputation: 1130

I doubt the problem is with that code. I ran into similar problems when I had badly written code without semi-colons at the end of each line. It all seems to work fine until I loaded a module then started getting errors but only sometimes. I turned on JavaScript validation in Titanium Studio (Preferences > Titanium Studio > Validation > JavaScript - everything by JSLint and Android UTF-8 Verifier) and fix all the errors in all your js files. Once you get the correct syntax everywhere, I suspect the problem will just go away.

Upvotes: 1

Related Questions