removeEventListener not working
I have not been able to get the removeEventListener to work and have included a simple example below.
Basically if you click button one, you get an alert event. Clicking button two should remove the click eventListener from button 1…. but its doesn't.
Anyone else ever had the same issue ?
Or am I doing something wrong here ?
var testButton = Titanium.UI.createButton({
top:30,
width:100,
height:33,
title:'button 1'
});
testButton.addEventListener('click', function() {
alert('Hello, world!');
});
var testButton2 = Titanium.UI.createButton({
top:70,
width:100,
height:33,
title:'button 2'
});
testButton2.addEventListener('click', function() {
testButton.removeEventListener('click');
});
win1.add(testButton);
win1.add(testButton2);
Thanks
Jamesy
5 Answers
-
Accepted Answer
function SayHello() { alert('Hello, world!'); } var click_b1 = testButton.addEventListener('click', SayHello); testButton2.addEventListener('click', function() { testButton.removeEventListener('click', SayHello); });
-
Same here - this seems to work IF there are no arguments passed into the function but it does not work if there are argumetns. WTF
-
try this way
var click_b1 = testButton.addEventListener('click', function() { alert('Hello, world!'); }); testButton2.addEventListener('click', function() { testButton.removeEventListener('click', click_b1); });
-
No that does not work either… it's really annoying the removeEventListener (and among many other things I have found) does not do what it's supposed to.
Does anyone know if this is known bug ?
-
Try this:
textArea.addEventListener('postlayout', eventListener = function(e) { textArea.removeEventListener('postlayout', eventListener); var height = e.source.rect.height; textArea.top = that.imageData.height - height - 5; });