Display HTML text in Spark TextArea

Below code works well ...

<?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:Declarations>
  <mx:HTTPService id="httpRSS" url="http://www.petefreitag.com/rss/" resultFormat="object" />
 </fx:Declarations>
  <s:Panel id="reader" title="Blog Reader" width="500">
  <mx:DataGrid width="485" id="entries" dataProvider="{httpRSS.lastResult.rss.channel.item}" click="{body.htmlText=httpRSS.lastResult.rss.channel.item[entries.selectedIndex].description}">
   <mx:columns>
    <mx:DataGridColumn dataField="title" headerText="TITLE"/>
    <mx:DataGridColumn dataField="pubDate" headerText="Date"/>    
   </mx:columns>
  </mx:DataGrid>
  <mx:TextArea id="body" editable="false" width="485" x="3" y="142" height="155"/>
 </s:Panel>
 <s:Button label="Load" x="10" y="329" click="{httpRSS.send()}"/>
 </s:Application>

But when Textarea changes to warp Textrea, as shown below

<s:TextArea id="body" editable="false" width="485" x="3" y="142" height="155"/>

Then htmlText does not support Spark Textarea. This gives rise to an error. How to view HTML text using the Text Area property.

+3
source share
7 answers

If you use the RichEditableText component , you can do it this way using the TextConverter class

var myStr:String = "I contain <b>html</b> tags!";           
myRichEditableText.textFlow = TextConverter.importToFlow(myStr, TextConverter.TEXT_FIELD_HTML_FORMAT);
+5
source

It can also be used in spark text.

var myStr: String = " html!"; textAarea.textFlow = TextConverter.importToFlow(myStr, TextConverter.TEXT_FIELD_HTML_FORMAT);

- , HTML- , TextFlowUtil.importFromString(yourHTMLString);

+3

TextArea docs. .. , HTML.

+1

body.textFlow = TextFlowUtil.importFromString(yourHTMLString);

+1

, . Halo TextArea, .

0

David Gassner's Flashbuilder 4 and Flex 4 have a section on this. Take a look at TextFlowUtil. If you want to embed HTML directly in Spark TextArea (or RichText / RichEditableText), you can use the content tag as a child, and then add p or span tags after that. Supported HTML tags are also part of the s namespace.

0
source

You can also use:

(myTextArea.textDisplay as StyleableTextField).htmlText = text;
0
source

Source: https://habr.com/ru/post/1756353/


All Articles