0

I have a drop down list that gets its data from a php web service method.This response is smthing like :

array('id'=>integer,'name'=>'lin')

When the page loads, I want to set the selected index to "lin" initially. How do I do this ?

Lin
  • 273
  • 4
  • 21

1 Answers1

0

you just need to set selectedIndex property of dropdownlist control.

ex.

dwl.selectedIndex = 1; // "Index of "lin"

you should do this.

var iIndex:int;

for(var i:int = 0; i < arrResponse.length; i++)
{

       // if(Array(arrResponse[i])[1] == "lin")

       if(Array(arrResponse[i]).name == "lin") {
            iIndex = i;

       }

}

dwl.selectedIndex = iIndex;
Cory Klein
  • 51,188
  • 43
  • 183
  • 243
JHK
  • 77
  • 5
  • But how is that gonna work ? I get the array from the database(its an array of arrays, I just wrote down the child array in my first post to make things clearer), and there's no way to determine its position from the webservice response... I mean to say... I may have some other name at selectIndex 1 and not necessarity "lin" – Lin Nov 30 '10 at 11:02
  • you can traverse response array in flex and find out the index and set as selectedindex. – JHK Nov 30 '10 at 11:51
  • yes thats exactly what I am looking for .. could you please elaborate ? – Lin Nov 30 '10 at 12:21