[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 440
  • Last Modified:

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 ?

reagards

reagrds
0
yarekGmail
Asked:
yarekGmail
1 Solution
 
scooby_56Commented:
perhaps and adaptation of this example will suit your needs


http://help.adobe.com/en_US/as3/dev/WS9dd7ed846a005b294b857bfa122bd808ea6-7fff.html#WS9dd7ed846a005b294b857bfa122bd808ea6-7ffe
package 
{ 
    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.lineStyle(3); 
            triangle.graphics.moveTo(30, 0); 
            triangle.graphics.lineTo(60, 50); 
            triangle.graphics.lineTo(0, 50); 
            triangle.graphics.lineTo(30, 0); 
            triangle.graphics.endFill(); 
     
            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; 
            addChild(textLine1); 
     
            var textElement:TextElement = new TextElement(str, format); 
            textBlock.content = textElement; 
            var textLine2 = textBlock.createTextLine(null, 300); 
            addChild(textLine2); 
            textLine2.x = textLine1.x - 30; 
            textLine2.y = textLine1.y + 15; 
        } 
    } 
}

Open in new window

0
 
dgofmanCommented:
text1.htmlText += "<b>Bold Text</b>";
0
 
puzzle-itCommented:
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:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
	
	<fx:Script>
		<![CDATA[
			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;
				ta.textFlow=TextFlowUtil.importFromString(s+s1.children().toString());
			}
			
		]]>
	</fx:Script>
	
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	
	<s:TextArea id="ta" creationComplete="init()" />
	
</s:Application>

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
0

Featured Post

Reclaim your office - Try the MB 660 headset now!

High level of background noise often makes it difficult for employees to concentrate fully on their jobs – or to communicate clearly on calls. The MB 660 headset helps you create a disruption free workspace.  

Tackle projects and never again get stuck behind a technical roadblock.
Join Now