Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1132] removeEventListener not removing events

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionInvalid
Resolution Date2011-04-15T02:44:53.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.5.0
ComponentsiOS
Labelsn/a
Reporterrjamesy
AssigneeReggie Seagraves
Created2011-04-15T02:44:53.000+0000
Updated2017-03-02T19:22:12.000+0000

Description

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.

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);

Comments

  1. Stephen Tramer 2011-04-15

    You should use code like the following:

       var win1 = Ti.UI.createWindow();
       
       var f = function() {
           alert('Hello, world!'); 
       }
       
       var testButton = Titanium.UI.createButton({
           top:30,
           width:100,
           height:33,
           title:'button 1'
       });
       testButton.addEventListener('click', f);
        
       var testButton2 = Titanium.UI.createButton({
           top:70,
           width:100,
           height:33,
           title:'button 2'
       });
       testButton2.addEventListener('click', function() {
           testButton.removeEventListener('click',f);
       });
        
       win1.add(testButton);
       win1.add(testButton2);
       win1.open();
       

    You are required to pass in a reference to the listener function at the time of removal.

  2. Lee Morris 2017-03-02

    Closed as invalid.

JSON Source