2 Replies Latest reply on Mar 27, 2012 6:03 AM by v-Jay

    Flex 4.6 displaying html text issue with tags like <b>,<i> in RichText control

    v-Jay

      Hi,

       

         I need to display html text in spark RichText control. I am using following approach;

       

       

      public var htmlText:String = "<b>hI</b> This is <i>test</i>.";
       
       richTxt.textFlow = TextFlowUtil.importFromString(htmlText);
       
       <s:RichText id="richTxt"></s:RichText>
       
      

       

       

       

       

       

       

      But the above approach does not work, it throws an error with character b.

      when i replaced <> braces  in the html string with &lt;&gt; , it shows complete string as it is in the RichText control with tags.

       

      But the above html text works fine with RichText  control if bold and italic formatting is provided with <span> tag.

       

       

      But I need to resolve the issue with basic tags like<b> and <i>, as the requirement is to display html text which might come with these tags.

      Also the requirement to use only spark control other wise mx control supports htmlText, which

      is easier.

       

      Can any one suggest how to resolve this issue with spark text controls? It would be really helpfull to me.

       

      Thanks.....

      public var str:String = "<span fontWeight='bold'>hI</span> This is test.";
      

        • 1. Re: Flex 4.6 displaying html text issue with tags like <b>,<i> in RichText control
          Patel Bharat Level 2

          Use as shown below, it would be helpful

           

          <?xml version="1.0" encoding="utf-8"?>

          <!--For more details: http://bharatria.wordpress.com -->

          <s:Application name="RichText_textFlow_test"

                                           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 flashx.textLayout.conversion.TextConverter;

                              ]]>

                    </fx:Script>

           

                    <fx:Declarations>

                              <fx:String id="htmlTextAsHTML"><![CDATA[<b>hI</b> This is <i>test</i>.]]></fx:String>

                    </fx:Declarations>

           

                    <s:RichText id="richTxt"

                                                  textFlow="{TextConverter.importToFlow(htmlTextAsHTML, TextConverter.TEXT_FIELD_HTML_FORMAT)}"

                                                  horizontalCenter="0" verticalCenter="0" />

           

          </s:Application>

          • 2. Re: Flex 4.6 displaying html text issue with tags like <b>,<i> in RichText control
            v-Jay Level 1

            Thanks Bharat,

             

            The TextConverter.importToFlow() works but do not render the image in img tag. as following;

             

              var  str:String="<b>hI</b> This is <i><b>test</b></i> <img source='assets/test.jpg' title='icon1' width='30' height='30'/> ";

             

             

            The img tag is handled properly by

             

            TextFlowUtil.importFromString() , but it do not handle tags like <b> ,<i>...so on. which is the root cause  of problem.

             

            Is there any solution for this ?

             

             

            Thanks