[TIMOB-3160] iOS: removeEventListener crashes when passed 'this'
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-11-05T15:46:33.000+0000 |
Affected Version/s | Release 1.5.1 |
Fix Version/s | Sprint 2011-22, Release 1.8.0 |
Components | iOS |
Labels | n/a |
Reporter | Jon Alter |
Assignee | Reggie Seagraves |
Created | 2011-04-15T03:38:21.000+0000 |
Updated | 2011-11-05T15:46:33.000+0000 |
Description
Application crashes when you try to use 'this' in removeEventListener to remove an addEventListener who's function you are in.
This code sample if from the code example at http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Animation-object"> http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI....
var view = Titanium.UI.createView({
backgroundColor:'red'
});
var animation = Titanium.UI.createAnimation();
animation.backgroundColor = 'black';
animation.duration = 1000;
animation.addEventListener('complete',function()
{
animation.removeEventListener('complete',this);
animation.backgroundColor = 'orange';
view.animate(animation);
});
view.animate(animation);
tested with 1.5.1, 1.6.0RC1, iOS SDK 4.2
Associated Helpdesk Ticket
http://developer.appcelerator.com/helpdesk/view/73881">http://developer.appcelerator.com/helpdesk/view/73881
You might use 'arguments.callee' instead of 'this' to solve this issue.
'arguments.callee' is itself that no name inner function.
animation.addEventListener('complete',function()
{ animation.backgroundColor = 'orange'; view.animate(animation); animation.removeEventListener('complete', arguments.callee); });
sorry, poor my english.
This is actually failing properly. The sample code in the API doc has been updated to show the proper way to do this.
this is pointing to the animation not the function.
Waiting for 1.7.0 to push which should update API docs.
While testing fix, corresponding Android bug was opened: TIMOB-5340
Fix verified in 1.8.0.v20111006001414. The application no longer crashes, but it also never transitions to orange. A new bug was filed for that issue: TIMOB-5459
Standardizing summary and labels.