getChild? getChildAt(0)?

You must Login before you can answer or comment on any questions.

Hello. I'm primarily an Actionscript 3/Flash developer. 'Views' appear to be very similar to the AS3 Display List, so I'm looking for similar means by which I can manipulate them:

getChild(); getChildAt(0);

Do the above methods exist in some form or another? I realize getChildren does, however I can't seem to do anything useful with the individual children of the object in question.

According to the API documentation it should return an array:

'textbox' being a previously instantiated TextArea.

'datelabel' being a previously instantiated Label.

'newslabel' being a previously instantiated Label.

textbox.add(datelabel);
textbox.add(newslabel);
 
var chld = textbox.getChildren;
for(var c = 0; c < chld.length; c++) {
    Titanium.API.info(chld[c]);
}
However, the above returns nothing. Perhaps I'm misunderstanding how I should be using getChildren.
var chld = textbox.getChildren;
Titanium.API.info(chld[0]);
The above returns undefined.

However, simply doing this:

var chld = textbox.getChildren;
Titanium.API.info(chld);
Does return all the children. How to access them individually though?

So, what's the best method for getting at the individual children of any particular view/object?

Thanks for any illumination.

3 Answers

Instead of trying to use the property getChildren try using the method. So instead do:

var chld = textbox.getChildren();
Titanium.API.info(chld);
and if you just want a single one in particular:
var chld = textbox.getChildren(0);
Titanium.API.info(chld);

UI elements are really just objects and objects are passed by reference in JS so I like just adding a name to my parent view to reference specific elements in that view..

var view = Ti.UI.createView();
 
   view.label1 = Ti.UI.createLabel();
   view.add(view.label1);
 
//then later 
    view.label1.text = "update text later"!

Your Answer

Think you can help? Login to answer this question!