I was working on a search feature for my RocketFM project and I ran in to a couple of things that I thought I would share. If your a Flex developer you probably already know this but for those of us who just dabble in it this entry will help.
First not really my tip but let's say we have a list of 30 files and we want to build a drop down list of unique file types. This way if a user wanted to only search for a specific file type they could. First I am looping over my files array and for each item I want to check if that file type is already in my fileTypes array, if its not I add it. To do so you can use the array class method indexOf. If indexOf returns a -1 then it does not contain that value so you can insert it into the array.
So here is where I was not really sure what to do. I need a default value for the combo box. This could either say select a file filter or something like show all file types. Your initial thought is to just add that in manually before the code above and then pre select it. This was my initial attempt and I just found some problems with pre selecting it so I thought there had to be a better way, and there is. Below is my search form and as you can see the combo box has a propmt attribute. This is the initial value of the combo box and perfect for our Select A File Filter message.
So far so good, but you will quickly run into another problem. When the user selects a filter there is no way to again select that initial value. In my form you will notice a clear button, using some code we can reset our form to its initial state, and that includes our combo box. If you set the combo boxes selectedIndex to -1 it will reset it back to the prompt message. Nothing special but it comes in handy!
