PDA

View Full Version : another comboBox problem ???


vosgien
11-04-2002, 06:50 AM
Hi,
I feel bit awkward asking this Q. Why ? Well I've done quite an extensive search on this forum and it seems there are a million and one Q.'s re the comboBox, I am beginning to think this component is not so good. I have also spent time at MM and in F1, so maybe it is just a small piece of code and I can't see the wood for the trees!!
Basically I have a combo box on stage and when user clicks on the drop down a dynamic text box is populated with the users choice. Using this code :


//this fills the comboBox list
sex = new Array("Sex", "Female", "Male");
//
for(i=0;i<sex.length;i++){
sexBox.addItem(sex[i]);
}
//
//this fills the text box sexSelect

sexBox.setChangeHandler("onItemPicked");
onItemPicked=function(){
sexSelect = (sexBox.getSelectedItem().label);
}

Now, that works absolutely fine, no probs........ except when I put a second comboBox on stage using this code :

ages = new Array("Age group","18 -25","26 - 35", "36 - 45","46 - 55", "over 55");

//
for (i=0;i<ages.length;i++){
ageGroup.addItem(ages[i]);
}
//
ageGroup.setChangeHandler("onItemPicked");
//
onItemPicked = function(){
ageSelect=(ageGroup.getSelectedItem().label);
}

The first dynamic text box, and I assume the first changeHandler are completely ignored.
I have tried many different ways of doing this but it don't happen.
Anyways, I have posted a testfile for anyone who has the time to look, but it is doin' my 'ed IN

Cheers

Vosgien

pom
11-04-2002, 10:09 AM
Well, it's normal that it doesn't work, as you redefine the onItemClick function. One solution would be to do:sexBox.setChangeHandler("onItemPicked2");
onItemPicked2=function(){
sexSelect = (sexBox.getSelectedItem().label);
}pom :)

i++
11-04-2002, 10:12 AM
hi vosgien,

the problem is that both functions (setChangeHandler) have got the same name.
the second overwrites the first function. just give the function different names and it should work.
ages = new Array("Age group","18 -25","26 - 35", "36 - 45","46 - 55", "over 55");

//
for (i=0;i<ages.length;i++){
ageGroup.addItem(ages[i]);
}
//
ageGroup.setChangeHandler("onAgePicked")
onAgePicked = function(){
ageSelect=(ageGroup.getSelectedItem().label);
}
//
//
sex = new Array("Sex", "Female", "Male");
//
for(i=0;i<sex.length;i++){
sexBox.addItem(sex[i]);
}
//
sexBox.setChangeHandler("onSexPicked");
onSexPicked=function(){
sexSelect = (sexBox.getSelectedItem().label);
}

hope it helps.

i++

vosgien
11-04-2002, 11:40 AM
Hi,
Thanks to you both, I knew what the problem was , but couldn't figure out a way to resolve it, and believe me when I say I really did try, but as ever, the thing that stops me progressing to "Flash Guru" status is my inate inability to see the wood for the trees, thank you both again for your time

Cheers

Vosgien

pom
11-04-2002, 01:43 PM
I believe it is "see the forrest from the tree". C'est l'arbre qui cache la forÍt, quoi :D

pom :)

zerooito
07-09-2003, 01:38 AM
You can create just one function for the clickHandler
and use it for multiples combo boxes...

try something like this:

create a new flash file and create two combo boxes
give them the following names:

combo1
combo2
put the changeHandler of them as: doit

and so, put this code at the frame 1:

// it's the change handler function
function doit(who){
trace(eval(who).getSelectedItem().label);
}
// it's the populate script for the combos
for(a=1;a<20;a++){
combo1.addItem(chr(64+a)+"1");
combo2.addItem(chr(64+a)+"2");
}


whenever your components call a clickHandler, they already pass the name of the component whom is calling the function.

so... you just have to give it a reference name inside the function.

in the function I typed above the reference name is WHO.

I hope that's clear.

Zerooito