2 Replies Latest reply on Jan 13, 2011 7:57 AM by _spoboyle

    Get select data value from Combobox

    JoGlez

      Hi all,

          I am having a major issue while trying to obtain the selected items value through the change event in a combobox.  below is my code.. I really do need help as soon as possible...Thanks in advanced

       

      public var test:ArrayCollection = new ArrayCollection([
                  { Id:"one", Amount:2000 },
                  { Id:"two", Amount:1000 },
                  { Id:"three", Amount:200 } ]);

      protected function regionCB_changeHandler(event:ListEvent):void
                     {
                        Alert.show(//tried so many things here to acces the items amount field.. nothing is working
                     }
      <s:ComboBox change="regionCB_changeHandler(event)" dataProvider="{test}" labelField="Id" id="regionCB" visible="false" />
        • 1. Re: Get select data value from Combobox
          Zolotoj Level 3

          Did you try selectedItem.Amount?

          • 2. Re: Get select data value from Combobox
            _spoboyle Level 4
            <?xml version="1.0" encoding="utf-8"?>
            
            <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
            
                                   xmlns:s="library://ns.adobe.com/flex/spark" 
            
                                   xmlns:mx="library://ns.adobe.com/flex/mx">
                
                <fx:Script>
                    <![CDATA[
                        import mx.collections.ArrayCollection;
                        import mx.controls.Alert;            
                        import spark.events.IndexChangeEvent;
                        
                        [Bindable]
                        public var test:ArrayCollection = new ArrayCollection([
                            { Id:"one", Amount:2000 },
                            { Id:"two", Amount:1000 },
                            { Id:"three", Amount:200 } ]);
                        
                        protected function regionCB_changeHandler(event:IndexChangeEvent):void
                        {
                            var combo:ComboBox = event.target as ComboBox;
                            var obj:Object = combo.selectedItem;
                            Alert.show(obj.Id +": " + obj.Amount);
                        }
                    ]]>
                </fx:Script>
                
                <fx:Declarations>
                    <!-- Place non-visual elements (e.g., services, value objects) here -->
                </fx:Declarations>
                
                <s:ComboBox change="regionCB_changeHandler(event)" dataProvider="{test}" labelField="Id" id="regionCB" visible="true" />
            
            

             

            </s:WindowedApplication>

             

            sorry some of "'s in the Alert.show have been removed by the syntax highlighting should be

            Alert.show(obj.Id +": " + obj.Amount);