PDA

View Full Version : [AS2] Problem selecting first value in combobox


theMonitor
10-26-2009, 12:14 PM
I'm using a combobox component that I'm populating with a five-element array, as follows:

0 All
1 Bakery
2 Diary
3 Deli
4 Drink

And because I don't want "All" displaying in the text box, I've added the line

dropDown.text = "Select here..."

once the combobox is populated. Unfortunately, when I test the combobox and open the list, "All" is at the top of the list but already selected, so that when I click it, nothing happens. The rest of the items work fine.

Could someone tell me how to disable the first item, so that it's not automatically selected when the list opens and therefore can be clicked?

galak
10-26-2009, 04:10 PM
why don't you just add a first item that is the "select an item" text, with no data. and in your listener function you tell it not to do anything if there's no data.

so your drop down would be populated as such :

0 Select an item
1 All
2 Bakery
3 Diary
4 Deli
5 Drink

theMonitor
10-26-2009, 04:50 PM
The problem then (unless I've mis-read your instructions) is that "Select an item..." appears not just in the text box when the combobox is unopened, but also at the top of the drop-down list. I know it sounds a bit nit-picky, but what I really wanted was a title that didn't show up twice.

Sorry if I didn't explain myself very clearly.

galak
10-27-2009, 01:01 AM
Ok then, why don't you add a listener on the "close" event, instead or even along with the "change" event, in that case even if you click on an already selected item, which is the case for the first one, it will return the value.

If you don't want the event to trigger again on close afterwards, just put a condiiton in it that disables or deletes the "close" event once a "change" has occurred.

theMonitor
10-27-2009, 09:52 AM
Good idea. In the end what I did was just listen for the 'close' event instead of the 'change ' event, which seems to do the trick.

Thanks for your advice.