Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-5340] Android: event listener is not found when passed 'this'

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionInvalid
Resolution Date2016-08-22T17:13:24.000+0000
Affected Version/sRelease 1.8.0
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, animate, eventlistener
ReporterAlan Vaghti
AssigneeIngo Muschenetz
Created2011-09-22T15:45:58.000+0000
Updated2017-03-16T21:37:00.000+0000

Description

1) Use the app.js below in a new project 2) Launch application Expected results: View animates from red to orange to black. Actual results: View remains red. Notes: Logcat keeps returning "listener not found for eventName 'complete'" Issue was discovered when testing iOS fix for TIMOB-3160 Code sample is essentially the example from: http://developer.appcelerator.com/apidoc/mobile/1.0/Titanium.UI.Animation
var win = Ti.UI.createWindow({ backgroundColor: 'purple' });

var view = Titanium.UI.createView({
   backgroundColor:'red'
});
var animation = Titanium.UI.createAnimation();
animation.backgroundColor = 'black';
animation.duration = 4000;
animation.addEventListener('complete',function()
{
   animation.removeEventListener('complete',this);
   animation.backgroundColor = 'orange';
   view.animate(animation);
});
view.animate(animation);

win.add(view);

win.open();

Comments

  1. Wilson Luu 2011-12-16

    Bug persists on: SDK build: 1.8.0.1.v20111216124633 Devices: LG Slate (3.1) on V8, Droid 1 (2.2.2) on Rhino
  2. Chris Barber 2016-08-22

    this does not refer to the reference to callback function, but rather the global scope. removeEventListener() expects the second argument to be a function, not an object. You need to name the function and pass in the reference to the function like this:
       var win = Ti.UI.createWindow({ backgroundColor: 'purple' });
       
       var view = Titanium.UI.createView({
          backgroundColor:'red'
       });
       
       function callback() {
          animation.removeEventListener('complete', callback);
          animation.backgroundColor = 'orange';
          view.animate(animation);
       }
       
       var animation = Titanium.UI.createAnimation();
       animation.backgroundColor = 'black';
       animation.duration = 4000;
       animation.addEventListener('complete', callback);
       view.animate(animation);
       
       win.add(view);
       
       win.open();
       
  3. Lee Morris 2017-03-16

    Closing ticket as invalid.

JSON Source