views:

1802

answers:

2

Hey everyone.. I'm really new to flash. I have a combo box and I am using the 'selectedIndex' property to give it a default value (a value that is at the first(0) index). Setting this property in my ActionScript does select the value in the dropdown but it does not add the selected value to the combo box's text area. How do you do this? Any selection I make has no affect on the text area.

Here is a sample of my code. The combo box list is populated fine. And the value is selected IN THE LIST. However, once you select a value in the list the combo box's list closes and nothing resides in the combo box's text field.

    comboBoxData.insert(0, {data:1, label:"Show me something specific"});
  for (i in animations) {

   comboBoxData.push({data: i.uri ,label: "somevalue"});
   }    
  comboBox.dataProvider = comboBoxData;
  comboBox.selectedIndex = 0;
  comboBox.text = comboBox.selectedIndex;

  this._lockroot = true;

My solution is using AS 2.

Thanks!

-Nick

+1  A: 

i think you need to add some code. i don't really understand. do you have a text area and a combobox? if that's the case then you could do something like this to give the selectedIndex to the text area

combo_cmb.selectedIndex=1;
text_txt.text=c.selectedIndex;
var listenerObjectPM:Object = new Object();
listenerObjectPM.change = function(eventObject:Object) {

     text_txt.text=combo_cmb.selectedIndex;

}
combo_cmb.addEventListener("change", listenerObjectPM);

if you want to print in the text area the label you can change the value of text_txt.text=combo_cmd.selectedItem.label; or if you want to print the data change it to text_txt.text=combo_cmb.selectedItem.data;. if this is not the case you can write the code so i can better understand what you are trying to do.

doamnaT
I want the combo box to simply display the selected value. This would be default behavior in any other language I have used. The combobox is made up of three components: A list, a butoon, and a text field. I want the text field that IS the combo box to be populated.
Nick
you mean like thiscombobox.addItem("label", data);?
doamnaT
the line should go in a for loop to include the entire list. By the way, the list is populated? Anyway i think a piece of code would clarify the problem.
doamnaT
I included a sample of my code. The problem is not in populating the list or selecting the value in the list. The problem is getting the selected value to appear in the combo box after it has been selected. In win forms.. this would be default behavior. You select a value from the list and that value now resides in the combo box until it is changed again.
Nick
A: 

It should be default behaviour as you stated but I had the same issue and this fixed it for me on the selection change event handler.

e.target.textField.text = e.target.selectedItem.label;
Ashley Swatton