5 Replies Latest reply on Aug 18, 2006 8:45 AM by JennHysuick

    HTML Character Entities in a ComboBox

    JennHysuick Level 1
      I was wondering if anyone knew of anyway to make HTML character entites appear in a combo box? I want to create a combobox selection of various chemical elements (like H20), and I have a chemical font that I'd like to use, which will translate the &#num; into the character properly. I can do this in a text area, but given that I need to put them in a combobox, I was hoping someone knew how to do this.

      thanks!

      ~~Jenn~~
        • 1. Re: HTML Character Entities in a ComboBox
          peterent Level 2
          You first need to embed your font. This is so that anyone who uses your SWF will have the font on their machine.

          Then you need an itemRenderer for your ComboBox. This might work (I haven't tried it, so I am guessing):

          <mx:ComboBox ...>
          <mx:itemRenderer>
          <mx:Component>
          <mx:Text htmlText="{data.label}" />
          </mx:Component>
          </mx:itemRenderer>
          </mx:ComboBox>
          • 2. Re: HTML Character Entities in a ComboBox
            peterent Level 2
            I just tried it. That does produce HTML in the dropdown, but not in the control selection. Will require more investigation.
            • 3. Re: HTML Character Entities in a ComboBox
              peterent Level 2
              Create a class that extends ComboBox and override the updateDisplayList and measureText functions. Then use that new ComboBox in your code:

              <local:HtmlComboBox .. xmlns:local="components.*".>
              <local:itemRenderer>
              <mx:Component>
              <mx:Text htmlText="{data.label}" />
              </mx:Component>
              </local:itemRenderer>
              </local:HtmlComboBox>

              Put this into a folder called "components" and name the file HtmlComboBox.as

              package components
              {
              import mx.controls.ComboBox;
              import flash.text.TextLineMetrics;

              public class HtmlComboBox extends ComboBox
              {
              public function HtmlComboBox()
              {
              super();
              }

              override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
              {
              super.updateDisplayList(unscaledWidth,unscaledHeight);

              var s:String = textInput.text;
              textInput.htmlText = s;
              }

              override public function measureText(text:String):TextLineMetrics
              {
              return measureHTMLText(text);
              }

              }
              }
              • 4. Re: HTML Character Entities in a ComboBox
                JennHysuick Level 1
                Peter,

                Thank you SOO much for your help - it did seem to work sort of (unless I'm still doing something wrong). If I put in <mx:Text htmlText="&#num;"/> in my combo box, the entity display properly, but what I need it to do is to use an array as the dataprovider, and the array contains strings of the entities (ex: H&#num;O), and all I get displayed in the comboBox is the literal string, rather than the actual entities. Is there some other way to get the combobox to interpret the variables in the array dataprovider?

                Thanks!

                Jenn
                • 5. Re: HTML Character Entities in a ComboBox
                  JennHysuick Level 1
                  Peter,

                  I managed to find the answer to my question just by playing around with the code. In order for the array with the character in it, I needed to use <mx:Text htmlText="{data}"/> in the HTMLComboBox component, rather than htmlText="{data.label}".

                  Now on the fun task of changing all my variables to use the html characters...

                  Once again, Thank you for your help! I really appreciate it!

                  ~~Jenn~~