views:

89

answers:

1

I have a Flex application which references a separate MXML file as a template for a custom component. I create instances of the component dynamically several times in my program, but I need to get a handle that will allow me to modify that instance of the component as desired.

I pass specific information to this component on instantiation using bindable public variables in the component's MXML file. I add it to my main program using addChild().

I want to update the component's progressbar as necessary and I want to remove it from the box to which I addChild'd it.

What's the easiest/best way to get a variable that will give me predictable access to each component so I can easily manipulate the components as necessary? Some research suggests creationComplete, but I decided it was faster to just ask than to go through lots of different experiments and come up blank.

Thanks for all the help. : )

+2  A: 

Can you not just keep a list of your components in an array? Presumably you have an object reference when you create them and call addChild() on their parent. Why not just put them in an array at the same time?

var list_of_controls:Array = new Array();
var new_Object:<yourType>;

new_Object = new <yourType>();
parent.addChild(new_Object);
list_of_controls.push(new_Object);

then you can get at them...

var my_Object:<yourType>;
for each (my_Object in list_of_controls)
{
    // do something
}

You would have to make sure you dispose of them properly when you re done because the reference in your array would keep them in existence until cleared.

If you decide that you want to use getChildren() instead - which you could - take the time to read the documentation because I think it returns a new array with each call.

I hope that helps.

Simon