Skip to main content
Participating Frequently
April 7, 2010
Question

TextFlowUtil.importFromString Problems

  • April 7, 2010
  • 1 reply
  • 2615 views

Hello,

With the Halo TextArea, and going back a long time, there was always a nice, simple htmlText property that at least provided some basic HTML formatting automatically.

This Spark TextArea and associated TextFlow and TextFlowUtil.importFromString() has me completely frustrated.

If I have this simple little string:

var string:String = "Hello <b>World</b>";

and I try to run:

TextFlowUtil.importFromString(string);

I get greeted with this error:

Error: Unknown element b

What is the trick to getting any arbitrary HTML string to be rendered as HTML so that it can be attached to a Spark TextArea?

This topic has been closed for replies.

1 reply

Peter_deHaan
Participating Frequently
April 7, 2010
Peter_deHaan
Participating Frequently
April 7, 2010

Or more specifically,

<?xml version="1.0" encoding="utf-8"?>
<s:Application 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;
           
            private function init():void {
                var string:String = 'Hello <b>World</b>';
                rt.textFlow = TextConverter.importToFlow(string, TextConverter.TEXT_FIELD_HTML_FORMAT);
            }
        ]]>
    </fx:Script>
   
    <s:RichText id="rt" creationComplete="init();" />
   
</s:Application>

Peter

emansouriAuthor
Participating Frequently
April 7, 2010

Thank you - this helps.  But my problem now is I have a Spark TextArea incorporated into an ItemRenderer attached to a Spark List.

The text in the TextArea only becomes visible after the TextArea is clicked on or the List is scrolled.

Is there an easy remedy for this?

<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                    xmlns:s="library://ns.adobe.com/flex/spark"
                    xmlns:mx="library://ns.adobe.com/flex/mx"
                    alpha.normal="1.0"
                    alpha.hovered="0.5"
                    alpha.selected="1.0">
     <fx:Script>
          <![CDATA[
               import flashx.textLayout.conversion.TextConverter;
               
               import mx.events.FlexEvent;
               
               private function init(event:FlexEvent):void
               {
                    description.textFlow = TextConverter.importToFlow(data.description,TextConverter.TEXT_FIELD_HTML_FORMAT);
               }

          ]]>
     </fx:Script>
     <s:layout> 
          <s:VerticalLayout    
               paddingLeft="5"  
               paddingRight="5" 
               paddingTop="5"  
               paddingBottom="5" /> 
     </s:layout> 
     
     <s:states>
          <s:State name="normal"/>
          <s:State name="hovered"/>
          <s:State name="selected"/>
     </s:states>
     
     <s:VGroup percentWidth="100">
          <s:TextArea textFlow="{TextConverter.importToFlow(data.description,TextConverter.TEXT_FIELD_HTML_FORMAT)}" id="description" percentHeight="100" percentWidth="100" creationComplete="init(event)"/>
     </s:VGroup>
     
</s:ItemRenderer>