Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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.

— asked March 22nd 2010 by Allen Firstenberg
  • 1.0.0
  • animate
  • animation
  • crash
  • documentation
  • event
  • events
  • iphone
  • mobile
  • remove
  • removeeventlistener
0 Comments

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

    — answered May 11th 2011 by freshteapot #
    permalink
    0 Comments
  • 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});
            });
        });
    });
    
    — answered March 22nd 2010 by William Xue
    permalink
    0 Comments
  • 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.

    — answered March 22nd 2010 by Allen Firstenberg
    permalink
    0 Comments
  • Your answer here was the clearest on the forum. Your example was better than the one in the docs. Thanks and great work man.

    — answered May 1st 2011 by Greg Adkins
    permalink
    1 Comment
    • Fantasic - been looking for something like this

      — commented June 12th 2011 by Nick Milner
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.