Titanium Community Questions & Answer Archive

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

get child at

I was wondering if there's a way to get number of children in a particular view. For instance, I want to get the total number of children in a scroll view then animate fade out and then delete it. Below is the code I'm trying to achieve coming from an AS3 background. Also, the reason I assigned hide.i = x is because I don't know how to achieve a delegate in Ti. Therefore, it's hacked up that way.

var numChildren = scrollView.numChildren;
for (var x = 0; x < numChildren; x++) {
    var anim = Titanium.UI.createAnimation();
    hide.opacity = 0;
    hide.duration = 150;
    hide.delay = 75*x;
    hide.id = x;
    scrollView.getChildAt(x).animate(hide);
    hide.addEventListener('complete', function(event) {
        var child = scrollView.getChildAt(event.source.id);
        scrollView.remove(child):
    }
}

Thanks!

— asked July 2nd 2010 by Thai Huynh
  • child
  • children
  • num
  • remove
0 Comments

1 Answer

  • For the benefit of others going forward, here's one possible solution.

    var elements = scrollView.getChildren();
    
    for (var idx in elements){
     //do something
     Ti.API.info(JSON.stringify(elements[idx]); 
    }
    
    — answered February 18th 2014 by Michael Stelly
    permalink
    0 Comments
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.