Hi,
The bug is that you are continuing through the loop even after you have
found the employeeStateId you are looking for. What you really want is
something like:
...
if( employeeStateId == stateCB.dataProvider[i].stateId ) {
stateCB.selectedIndex = employeeStateId ;
return;
}
...
Also, your code is a little inefficient in that it sets the
selectedIndex to 0 for every item that is *not* the value you are
looking for, instead of setting it to 0 once if the value is not found.
HTH,
Doug
--- In [email protected], "malik_robinson" <[EMAIL PROTECTED]>
wrote:
>
>
> Hi,
>
> I am trying to set the selectedIndex of my "U.S. States" custom combo
> box equal to what the user has stored in their record in our database.
> Someone posted a link to a similar tutorial, but I could not get it to
> work and I think it seems to be slightly different than what I am
doing.
> When the screen loads, the state the user is associated with should be
> selected, otherwise set the selectedIndex equal to 0.
>
> As of now it does not select anything it seems the condition where I
> test for equality fails and I always get the selectedIndex set to 0.
>
> The code:
>
> public function initStateCB(employeeStateId:Number):void {
>
>
> for ( var i:int=0; i< stateCB.dataProvider.length; i++ ) {
> if( employeeStateId == stateCB.dataProvider[i].stateId ) {
> stateCB.selectedIndex = employeeStateId ;
> }
> else {
> stateCB.selectedIndex = 0;
> }
> }
>
> } // close function
>
>
>
> <mx:FormItem label="State:">
> <comp:StateCombo id="stateCB" dataProvider="{model.stateList}"
> labelField="stateName"
>
creationComplete="initStateCB(model.employeeProfileArray[0].stateId)"/>
> </mx:FormItem>
>