flex text engine HTML

Posted on 2011-10-24
Last Modified: 2012-05-12
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 ?


Question by:yarekGmail
    LVL 12

    Expert Comment

    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(); 
      , 1); 
      , 0); 
      , 50); 
      , 50); 
      , 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

    LVL 29

    Expert Comment

    text1.htmlText += "<b>Bold Text</b>";
    LVL 2

    Accepted Solution

    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="" 
    			   xmlns:mx="library://" 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

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
    Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
    This video discusses moving either the default database or any database to a new volume.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now