1 Reply Latest reply on Feb 15, 2012 3:12 AM by TheGarfunkal

    extended combobox to include selecteditem (flex 3)

    TheGarfunkal Level 1

      I've got myself into a bit of a pickle!

       

      I needed to preselect a value in a combobox based on something coming back from a httpservice call.   I'venever really done much by way of extending controls so I was pretty happy with myself till i realised i'd not done it properly.  then i felt stupid, and then i came on here for help

       

      so i have this as class...

       

      package com.rsagroup.flex.iReview.baseclasses.amendDeliverable

      {

                import com.rsagroup.flex.iReview.model.ModelLocator;

       

                import mx.collections.ArrayCollection;

                import mx.controls.ComboBox;

                import mx.events.FlexEvent;

                import mx.messaging.AbstractConsumer;

       

       

                public class SelectableItemComboBoxBase extends ComboBox

                {

                                    [Bindable]

                                    protected var _modelLocator:ModelLocator = ModelLocator.getInstance();

       

       

                                              private var _arrayCurValue:String;

                                              private var _arrayInitValue:String;

       

       

                          public function SelectableItemComboBoxBase()

                          {

       

       

                                    super();

                                     addEventListener(FlexEvent.CREATION_COMPLETE, this.myComboBox);

                          }

       

                          public function get arrayCurValue():String

                          {

                                    return  _arrayCurValue

                          }

       

                          public function set arrayCurValue(value:String):void

                          {

                                    _arrayCurValue = value;

                          }

       

                          public function get arrayInitValue():String

                          {

                                    return  _arrayInitValue

                          }

       

                          public function set arrayInitValue(value:String):void

                          {

                                    _arrayInitValue = value;

                          }

       

       

       

                          public  function myComboBox(event:FlexEvent):void

                          {

                                    var aDP:ArrayCollection =  event.currentTarget.dataProvider;

                                    var sDataValueInit:String = _arrayInitValue;

       

                                    trace(" control = " +  _arrayCurValue)

       

                                    var sDataValueCur:String;

                                    for ( var i:Number=0; i<aDP.length; i++ )

                                     {

                                              sDataValueCur = aDP[i][arrayCurValue];

       

       

                                              trace(" sDataValueCur = " + sDataValueCur + " sDataValueInit = " + sDataValueInit)

       

       

                                              if ( sDataValueCur == sDataValueInit )

                                              {

                                                        event.currentTarget.selectedIndex = i;

                                                        break;

                                              }

                                     }

                          }

                }

       

      }

       

      and I am using it like this:

       



      <mx:FormItem label="Area">



      <baseclasses:SelectableItemComboBoxBase id="areaCombo" arrayCurValue="Area"  arrayInitValue="{_modelLocator.amendDeliverableArea}" labelField="Area" dataProvider="{_modelLocator.area}"/>


      </mx:FormItem>

       

      obviously my problem this will only fire on creation complete and it may required over and over  - and i am a dunce.

       

      I assume the whole methodology i've used is incorrect - can someone give me some pointers, or help me with getting it to fire when its required!

       

      any help is greatfully accepted