1. If accessing the ComboBoxes you'll create by an index number is sufficient, 
declare an instance var of type Array:

    private var comboBoxes:Array = [];

When you dynamically create a new ComboBox, simply add the reference onto the 
end of this Array:

    var newComboBox:ComboBox = new ComboBox();
    ...
    comboBoxes.push(newComboBox);

You can then access the i-th ComboBox as comboBoxes[i].

2. If you need to access them by some kind of name, declare an Object

    private var comboBoxes:Object = {};

and do something like

    var newComboBox:ComboBox = new ComboBox();
    ...
    comboBoxes["state"] = new ComboBox();

You can then access this ComboBox as comboBoxes["state"].

Gordon Smith
Adobe Flex SDK Team

From: [email protected] [mailto:[email protected]] On Behalf 
Of Brad Bueche
Sent: Saturday, June 13, 2009 3:48 PM
To: [email protected]
Subject: [flexcoders] Dynamically Naming Objects





I have a button that creates new combo boxes with dataproviders.   I can hard 
code things and create combo-boxes as much as I want but thats a little silly.  
I need to dynamically create new combo boxes and then reference them for 
hooking up the data providers and getting results etc.

I have figured out how to create dynamic variable names.  For instance:

this["cbx" + counter].x = xValue;
this["cbx" + 
counter].addEventListener(FlexEvent.CREATION_COMPLETE,createRemoteObject);
this["cbx" + counter].labelField = "Label";
addChild(this["cbx" + counter]);

The problem is that I cant figure out how to dynamically create a new ComboBox. 
 This is as far as I can get (and its wrong)

this["cbx" + counter]:ComboBox = new ComboBox();

brad

Reply via email to