PDA

View Full Version : ComboBox "addItem"-event..


Holmqvist
09-27-2007, 08:04 AM
Hi,

I've got a comboBox and I want to hide it if there is only one item in it.

I've tried to check it on the keyframe but that happens too soon, the comboBox won't be populated yet so length will always be 0. So I thought I'd check after an items been added (hide it on the first and show if there are more added after that), but I don't know any event that would work and my experiments have not been successful (nor google..)

Do you know how to do this with some event, or alternate solution?

lsatdown
09-27-2007, 08:55 AM
comboBox.addItem("item1");
comboBox.addItem("item1");
comboBox.addItem("item1");
comboBox.addItem("item1");
comboBox.addItem("item1");
if(comboBox.length = 1) {
comboBox._visible = false;
comboBox._enabled = false;
}
else {
comboBox._visible = true;
comboBox._enabled = true
};

lsatdown
09-27-2007, 08:56 AM
or:

comboBox.addItem("item1");
comboBox.addItem("item1");
comboBox.addItem("item1");
comboBox.addItem("item1");
comboBox.addItem("item1");
onEnterFrame = function() {
if(comboBox.length = 1) {
comboBox._visible = false;
comboBox._enabled = false;
}
else {
comboBox._visible = true;
comboBox._enabled = true
}
}

Holmqvist
09-27-2007, 02:07 PM
Well I guess the onEnterFrame one would work.. but I'm not too excited about using it. Got another solution that doesn't keep chewing resources when I'm done?

I add all items at one time, but it seems that if i hide it when I add something, it will become visible when the item is loaded in anyway, so I need to hide it when it's done, after the items been added. Or if there's some other way to go around it.

tg
09-27-2007, 04:11 PM
you could put all items you want to use in an array. if the length of the array > 1 then attach a combobox and use the array as the dataProvider, if it is not, then show your item however you have planned

Holmqvist
09-28-2007, 02:30 PM
Yea, that's a good solution but I think I need to add the combobox any case, cause i read the selected value on clicks to see if it's changed... so that would cause some trouble to me I'm not ready to deal with.