flex text engine HTML

Question is about Flex4 Text Engine:

I want to
1) add HTML text to textArea
I can load text like:
      var s:String='<p fontSize="12">TextArea with<span fontWeight="bold">TLF</span> block</p>';
      text1.textFlow = TextFlowUtil.importFromString(text1.text + s, TextConverter .TEXT_FIELD_HTML_FORMAT);

But I have no idea how to appen new text !

2) add an image to textArea

All this in the the new TLF : any idea ?


Who is Participating?
puzzle-itConnect With a Mentor Commented:
To append new formatted text in a text area you should make a new text flow composed by the content of old textflow and the new text to append, for  example
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
			import flashx.textLayout.conversion.ConversionType;
			import flashx.textLayout.conversion.TextConverter;
			import flashx.textLayout.tlf_internal;
			import mx.controls.Alert;
			import spark.utils.TextFlowUtil;
			private function init():void
				var s:String='<p fontSize="12">TextArea with<span fontWeight="bold">TLF</span> block</p>';
				ta.textFlow = TextFlowUtil.importFromString(s);
				var s1:XML=flashx.textLayout.conversion.TextConverter.export(ta.textFlow,
					flashx.textLayout.conversion.TextConverter.TEXT_LAYOUT_FORMAT,ConversionType.XML_TYPE) as XML;
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	<s:TextArea id="ta" creationComplete="init()" />

Open in new window

in the code above i use your code to insert in TextArea text a first time, then i recover the same layout text from TextArea, i clean it of <TextFlow></TextFlow> element, added by conversion method, i convert to string and append in TextArea
perhaps and adaptation of this example will suit your needs

    import flash.text.engine.*; 
    import flash.display.Sprite; 
    import flash.display.Shape; 
    import flash.display.Graphics; 
    public class GraphicElementExample extends Sprite 
        public function GraphicElementExample() 
            var str:String = "Beware of Dog!"; 
            var triangle:Shape = new Shape(); 
            triangle.graphics.beginFill(0xFF0000, 1); 
            triangle.graphics.moveTo(30, 0); 
            triangle.graphics.lineTo(60, 50); 
            triangle.graphics.lineTo(0, 50); 
            triangle.graphics.lineTo(30, 0); 
            var format:ElementFormat = new ElementFormat(); 
            format.fontSize = 20; 
            var graphicElement:GraphicElement = new GraphicElement(triangle, triangle.width, triangle.height, format); 
            var textBlock:TextBlock = new TextBlock(); 
            textBlock.content = graphicElement; 
            var textLine1:TextLine = textBlock.createTextLine(null, triangle.width); 
            textLine1.x = 50; 
            textLine1.y = 110; 
            var textElement:TextElement = new TextElement(str, format); 
            textBlock.content = textElement; 
            var textLine2 = textBlock.createTextLine(null, 300); 
            textLine2.x = textLine1.x - 30; 
            textLine2.y = textLine1.y + 15; 

Open in new window

text1.htmlText += "<b>Bold Text</b>";
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.