PDA

View Full Version : Creating a Dependant, Dynamic ComboBox from an array


paulio
10-22-2004, 09:48 PM
Good day all Here's my delima. i have an array of strings CSV (dataset)

i want to make a ComboBox dynamic from this array. (this array being a subset) from it's parrent.

//-- Begin code snipit ------------------------------
FSelectableListClass.prototype.makeDependent = function(multiDataProvider,master){
master.setChangeHandler("updateView",this);
this.multiDataProvider = multiDataProvider;
this.master = master;
};

FSelectableListClass.prototype.updateView = function(){
var selectedIndex = this.master.getSelectedIndex();
var dp = this.multiDataProvider[selectedIndex];
this.setDataProvider(dp);
}

cannedItem = new Array();

cannedItem [0] = "apple";
cannedItem [1] = "pear";
cannedItem [2] = "orange";
cannedItem [3] = "plum";

_root.attachMovie("FComboBoxSymbol","myComboBox1",1, {_x:5,_y:422} );
_root.attachMovie("FComboBoxSymbol","myComboBox2",2, {_x:5,_y:472});

theItemMainTypes = ["fruit","vegatables","Breads"];
myComboBox1.setDataProvider(theItemMainTypes);

theItemSubTypes = new Array();

theItemSubTypes.push([generateComboBoxData(cannedItem )]);
//-- the Above line is the one i am loosing my mind on. :)

theItemSubTypes.push(["carrot","lettuce","beans"]);
theItemSubTypes.push(["bread","bagel","muffin"]);

myComboBox2.makeDependent(theItemSubTypes,myComboB ox1);

//-- end code snipit ------------------------------

The generateComboBoxData(cannedItem) function returns the array as a sting like so: "apple","pear","orange","plum"

if i replace that above line with the values type in like so:

theItemSubTypes.push(["apple","pear","orange","plum"]);

Everything works perfectly.

I am about ready to toss my computer out the window and become a farmer. :)

I would be etarnally grateful if someone can point out the errors of my ways.

HELP ME>> :)

paul..

paulio
10-23-2004, 05:46 AM
Well come on people this was an easy one ;)

I should have looked closer at the

(["apple","pear","orange","plum"]);

duh it's an array. and i am tring to pass a string LOL.. for thoes of you who want a combo box that updates the second combo box based on the first combo's selection with the data from an array pass an array to the

theItemSubTypes

Works nicely.

Thanks fellow coders. for the support.

paulio
10-23-2004, 06:23 AM
Well here's the Working Example for you all to copy and paste.

//-- Begin Code Snipit ------------------------------------------
theFruit = new Array();
theFruit[0] = "apple";
theFruit[1] = "pear";
theFruit[2] = "orange";
theFruit[3] = "plum";

theVegs = new Array();
theVegs[0]= "Carrot";
theVegs[1] = "Beans";
theVegs[2] = "Mushrooms";
theVegs[3] = "Green Peppers";

theBread = new Array();
theBread[0] = "bagel";
theBread[1] = "Cereal";
theBread[2] = "Pasta";
theBread[3] = "Rice";

//-- Begin Functions / Classes ------------------------------------------
FSelectableListClass.prototype.makeDependent = function(multiDataProvider,master){
master.setChangeHandler("updateView",this);
this.multiDataProvider = multiDataProvider;
this.master = master;
};

FSelectableListClass.prototype.updateView = function(){
var selectedIndex = this.master.getSelectedIndex();
var dp = this.multiDataProvider[selectedIndex];
this.setDataProvider(dp);
}

//-- Begin Main Code ------------------------------------------
_root.attachMovie("FComboBoxSymbol","myComboBox1",1, {_x:5,_y:150} );
_root.attachMovie("FComboBoxSymbol","myComboBox2",2, {_x:5,_y:200});

myComboBox1.width = 500;
myComboBox2.width = 500;

theItemMainTypes = ["--Select One","fruit","vegatables","Breads"];
myComboBox1.setDataProvider(theItemMainTypes);

theItemSubTypes = new Array();
theItemSubTypes[0] = [""]; // Add Blank one for the --Select One selection
theItemSubTypes.push(theFruit); // pass an array to each position of the array.
theItemSubTypes.push(theVegs); // pass an array to each position of the array.
theItemSubTypes.push(theBread); // pass an array to each position of the array.

myComboBox2.makeDependent(theItemSubTypes,myComboB ox1);

//-- end Code Snipit. ---------------------------------------

Enjoy

Paul.