Search code examples
web-servicesdrop-down-menuflex4gumbo

Setting default Index for a Drop Down List in flex 4


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 ?


Solution

  • 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;