2 Replies Latest reply on Sep 16, 2009 11:31 AM by babo_ya

    Cannot set ComboBox selectedIndex during ComboBox creation?




      I have an outside dataprovider that properly fills in the values in the combo box.  However, there is no "default value" of the comboBox (selectedIndex == -1) and I cannot change this for a small amount of time.  Trying to set


      myComboBox.selectedIndex = 0;


      upon creationComplete doesn't work.  When I trigger the same event through a keypress, the selectedIndex properly updates and displays in the comboBox.  Essentially, I am looking for a way to display a default value in this comboBox (which is dependent on data; i.e. it will not always be the same.


        • 1. Re: Cannot set ComboBox selectedIndex during ComboBox creation?

          Can you post a small code snippet for this?


          I'll have a wee look and see what advice i can give!!

          • 2. Re: Cannot set ComboBox selectedIndex during ComboBox creation?

            Try this..


            package src




            import flash.events.*;


            import mx.controls.ComboBox;

            import mx.events.FlexEvent;


            public class ExtendedCombo extends ComboBox


            private var _defaultValue:String;


            public function ExtendedCombo()





            protected override function createChildren():void





            this.addEventListener(FlexEvent.CREATION_COMPLETE, onCreateCC);



            private function onCreateCC(event:FlexEvent):void


            textInput.text = _defaultValue;


            protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void


            super.updateDisplayList(unscaledWidth, unscaledHeight);



            public function get defaultValue():String


            return _defaultValue;


            public function set defaultValue(value:String):void


            _defaultValue = value;


            public function updateDefaultValue(v:String):void


            textInput.text = v;

            _defaultValue = v;








            and the main.mxml


            <?xml version="1.0"?>

            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

              creationComplete="init();" xmlns:src="src.*">





                  public var dp:Array = new Array("1", "2", "3" , "4");


                  private function clickHandler(event:MouseEvent):void


                  cmb.updateDefaultValue("New default value"); 







            <mx:Button label="update" click="clickHandler(event);" />

            <src:ExtendedCombo width="150" id="cmb" dataProvider="{dp}" defaultValue="Default" />



            hope this helps,



            1 person found this helpful