removeEventListener crashes
The following code is based on the code in the documentation in Ti.UI.Animation (https://developer.appcelerator.com/apidoc/mobile/1.0/Titanium.UI.Animation). The only changes were to create a window and add the view to that window.
var win = Titanium.UI.createWindow({
backgroundColor:'#cccccc'
});
win.open({
fullscreen: true
});
var view = Titanium.UI.createView({
backgroundColor:'red'
});
win.add( view );
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);
Running this in the iPhone emulator causes it to crash with the error
[INFO] Application has exited from Simulator
and no other messages. Commenting out the "removeEventListener" line causes the program to behave as expected.
4 Answers
-
I know you asked this a year ago…
Using the examples, spread around the documents:
animation.removeEventListener("complete",this);
This would crash my emulator.
The code below works. (Read the bit after for a disclaimer)
//table is a TableView... but can be anything. var animation = Titanium.UI.createAnimation(); animation.top = 45; animation.duration = 500; table.animate(animation); animation.addEventListener("complete",function(){ animation.removeEventListener("complete",function(){}); search.focus(); });
I cannot prove that the approach I have taken works as I dont know how to debug current "events in a listening state".
Equally, if it turns out that, this approach works. How does one go about contributing to the documents?
Github?
https://github.com/appcelerator/titanium_mobile/tree/master/apidoc/Titanium -
I don't think remove event listener is required here.
In the Kitchesink project. The sliding animation example has some code that might give you some insight.
button2.addEventListener('click', function() { // use inline style win.animate({right:-320, duration:500}, function() { win.animate({right:0, left:-320, duration:500}, function() { win.animate({right:0, left:0, duration:500}); }); }); });
-
William, while its true that my example doesn't require removeEventListener(), there are a couple of problems with your suggestion:
1) My code is more complicated, but does require removeEventListener, and similarly doesn't work.
2) I used the code example above because it is what Appcelerator provided in their documentation and it is a good minimal example of the problem. -
Your answer here was the clearest on the forum. Your example was better than the one in the docs. Thanks and great work man.