8 Replies Latest reply on Apr 18, 2008 6:15 PM by Peter deHaan

    Combox Box not displaying selected item

    kdennis4 Level 1
      Below is the code I'm using to try to capture and display the selected item from a ComboBox:

      private function changeProjectTypeSelection(event:Event):void{
      projectTypeChange.text+=event.currentTarget.selectedItem.cboProjectType + " " +
      event.currentTarget.selectedIndex + "\n";
      }


      Then the ComboBox:
      <mx:ComboBox fontSize="12" x="93" y="83" width="110" id="cboProjectType" dataProvider="{projectTypeArray}" labelField="projectTypeName" selectedIndex="0" click="changeProjectTypeSelection(event)"></mx:ComboBox>

      Then the TextInput:
      <mx:TextInput id="projectTypeChange" x="248.95" y="84" width="121"/>

      I know there's something wrong with the Actionscript code... just haven't figured it out. Any suggestions would be greatly appreciated!
        • 1. Combox Box not displaying selected item
          bitwyse Level 1
          Instead of using : event.currentTarget.selectedItem.cboProjectType
          Try using : event.target.selectedItem
          • 2. Combox Box not displaying selected item
            chris.huston.t10 Level 3
            Is projectTypeArray an ArrayCollection? Do you have a cboProjectType property in an object in your projectTypeArray? It looks like there is no projectTypeArray.cboProjectType value in your dataProvider which is why you are getting undefined in your output. What do you get if you try the below code:

            projectTypeChange.text+=event.currentTarget.selectedItem.projectTypeName + " " + event.currentTarget.selectedIndex + "\n";

            Vygo
            • 3. Re: Combox Box not displaying selected item
              kdennis4 Level 1
              With the code changed as follows:

              private function changeProjectTypeSelection(event:Event):void{
              projectTypeChange.text+=event.currentTarget.selectedItem.projectTypeName + " " +
              event.currentTarget.selectedIndex + "\n";
              }

              I get the first item with the the index showing in the textinput field like this:

              Brochure 0

              ??? Any clues what else I might be missing? Thanks for the input!
              • 4. Re: Combox Box not displaying selected item
                kdennis4 Level 1
                Ok... I've changed my code as follows:

                private function changeProjectTypeSelection(event:Event):void{
                var i:int;
                for(i=0;i<projectTypeArray.length;i++){
                if(projectTypeArray.getItemAt(i).projectTypeName == ?){
                projectTypeChange.text+=projectTypeArray.getItemAt(i).projectTypeName + "\n";
                //Alert.show(projectTypeArray.getItemAt(i).projectTypeName);
                }
                }
                }

                I need to figure out how to compare projectTypeArray.getItemAt(i).projectTypeName with ???(selectedIndex/Item)

                I hope this makes sense, and I hope there are more suggestions. Thanks again!
                • 5. Re: Combox Box not displaying selected item
                  kdennis4 Level 1
                  I've almost got it...

                  private function changeProjectTypeSelection(event:Event):void{
                  var i:int;
                  for(i=0;i<projectTypeArray.length;i++){
                  if(projectTypeArray.getItemAt(i).projectTypeName == event.currentTarget.selectedItem.projectTypeName){
                  projectTypeChange.text+=projectTypeArray.getItemAt(i).projectTypeName + "\n";
                  Alert.show(projectTypeArray.getItemAt(i).projectTypeName + "FirstAlert");
                  //Alert.show(event.currentTarget.selectedItem.projectTypeName + "SecondAlert");
                  }
                  }
                  }

                  I just can't seem to be able to reset the value in the textInput field. I've tried setting it equal to spaces in several places, but it won't change after the first selection. Any ideas? Thanks for any suggestions!
                  • 6. Re: Combox Box not displaying selected item
                    kdennis4 Level 1
                    Finally! Here is the solution:

                    private function changeProjectTypeSelection(event:Event):void{
                    var i:int;
                    for(i=0;i<projectTypeArray.length;i++){
                    if(projectTypeArray.getItemAt(i).projectTypeName == event.currentTarget.selectedItem.projectTypeName){
                    projectTypeChange.text=projectTypeArray.getItemAt(i).projectTypeName;
                    }
                    }
                    }
                    • 7. Re: Combox Box not displaying selected item
                      Garyl Woolworth Level 1
                      A much easier solution would be to bind the text property of the TextInput to the selectedItem of the ComboBox itself. An example would be as follows.

                      Everytime an item changes within the combo box it will dispatch the change event itself and update the bindings automatically.
                      • 8. Re: Combox Box not displaying selected item
                        Peter deHaan Level 4
                        kdennis4,

                        If you want to use ActionScript instead of a binding, you could also use the following code.

                        Peter