4 Replies Latest reply on Jun 25, 2008 6:03 AM by flexBeginner2008

    ComboBox setStyle on list

    flexBeginner2008
      Can anyone tell me please how do I set the color of list texts in a combobox?

      Thank you
        • 1. Re: ComboBox setStyle on list
          Gregory Lafrance Level 6
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
          <mx:ComboBox color="red">
          <mx:ArrayCollection>
          <mx:String>Fish</mx:String>
          <mx:String>Meat</mx:String>
          <mx:String>Veggies</mx:String>
          <mx:String>Candy</mx:String>
          <mx:String>Plastic</mx:String>
          </mx:ArrayCollection>
          </mx:ComboBox>
          </mx:Application>
          • 2. Re: ComboBox setStyle on list
            flexBeginner2008 Level 1
            Yes, indeed, but I want the text on the header to be on one color, and the labels of the list elements from the dropdown on another one. Can I do this from ActionScript?

            Thanks again
            • 3. Re: ComboBox setStyle on list
              Gregory Lafrance Level 6
              ----------------- classes/MyComboBox.as -------------------
              package classes
              {
              import mx.collections.ArrayCollection;
              import mx.controls.ComboBox;
              import mx.events.DropdownEvent;
              import mx.events.FlexEvent;

              public class MyComboBox extends ComboBox {
              private var arr:Array = ["Fish", "Meat", "Veggies", "Candy", "Plastic"];
              private var ac:ArrayCollection = new ArrayCollection(arr);

              public function MyComboBox() {
              super();
              addEventListener(FlexEvent.CREATION_COMPLETE, completeHandler);
              addEventListener(DropdownEvent.OPEN, openHandler);
              addEventListener(DropdownEvent.CLOSE, closeHandler);
              this.dataProvider = ac;
              }

              private function completeHandler(e:FlexEvent):void{
              textInput.setStyle('color','blue');
              }
              private function openHandler(e:DropdownEvent):void {
              this.setStyle('color', 'red');
              }

              private function closeHandler(e:DropdownEvent):void {
              this.setStyle('color', 'blue');
              }
              }
              }
              --------------- Test.mxml -------------------------
              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="init()">
              <mx:Script>
              <![CDATA[
              import classes.MyComboBox;

              private var myCB:MyComboBox = new MyComboBox();
              private function init():void{
              addChild(myCB);
              }
              ]]>
              </mx:Script>
              </mx:Application>
              • 4. Re: ComboBox setStyle on list
                flexBeginner2008 Level 1
                Great! This is what I was looking for.

                Thank you very much for your help