Clickboard for Multi-line text

679
3
Jump to solution
04-18-2013 01:17 PM
ShaningYu
Frequent Contributor
See the code below.  However, when I pasted the text content, the contents are in the same line.  How to solve this problem?  I want to display the contents line by line.  Thanks.

import flash.desktop.Clipboard;
import flash.desktop.ClipboardFormats;
private var richTextEditor:mx.controls.RichTextEditor = new mx.controls.RichTextEditor();
...
private function button_click():void {
                richTextEditor.text = txtX.text;
                richTextEditor.text += '\n' + txtY.text ;
                richTextEditor.text += '\n' + txtX.text ;
                richTextEditor.text += '\n' + txtY.text ;
                System.setClipboard(richTextEditor.text);
}
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
IvanBespalov
Occasional Contributor III
<?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">    <s:layout>   <s:VerticalLayout gap="10"         paddingBottom="10"         paddingLeft="10"         paddingRight="10"         paddingTop="10" />  </s:layout>   <fx:Script>   <![CDATA[    import mx.utils.StringUtil;    protected function onAddTimeClick(event:MouseEvent):void    {     var now:Date = new Date();     addTextToSparkComponent(now.toString());     addTextToMxComponent(now.toString());    }        private function addTextToSparkComponent(message:String):void    {     txtSpark.text = txtSpark.text.length > 0 ? StringUtil.substitute("{0}\n", txtSpark.text) : "";     txtSpark.text = StringUtil.substitute("{0}{1}", txtSpark.text, message);    }        private function addTextToMxComponent(message:String):void    {     while (message.search("\n") != -1) {      message = message.replace("\n", "<br>");     }     txtMx.htmlText = txtMx.text.length > 0 ? StringUtil.substitute("{0}<br>", txtMx.htmlText) : "";     txtMx.htmlText = StringUtil.substitute("{0}{1}", txtMx.htmlText, message);    }     protected function onAddInputClick(event:MouseEvent):void    {     var inputText:String = txtInput.text;     addTextToSparkComponent(inputText);     addTextToMxComponent(inputText);         }    ]]>  </fx:Script>     <s:Panel title="Inputs"     width="100%">      <s:VGroup width="100%"       height="100%"       gap="10"       paddingLeft="10"       paddingTop="10"       paddingBottom="10">           <s:Button label="Add now time"         click="onAddTimeClick(event)"/>        <s:Label text="Input smthing. Use 'ENTER' to make your text multiline." />        <s:TextArea id="txtInput" />        <s:Button label="Add inputs"         click="onAddInputClick(event)"/>       </s:VGroup>     </s:Panel>    <s:Panel title="Outputs"     width="100%"     height="100%">      <s:HGroup width="100%"       height="100%"       paddingLeft="10"       paddingTop="10"       paddingBottom="10">        <s:VGroup width="100%"        height="100%">          <s:Label text="mx.controls.RichTextEditor" />          <mx:RichTextEditor id="txtMx"             width="100%"            height="100%"            showControlBar="false"/>         </s:VGroup>        <s:VGroup width="100%"        height="100%">          <s:Label text="spark.components.RichTextEditor" />          <s:RichEditableText id="txtSpark"          width="100%"          height="100%" />         </s:VGroup>       </s:HGroup>       </s:Panel>   </s:Application>


P.S. SDK 4.9.0
P.S.2 It's not ArcGIS Flex API question, don't you think? Adobe learning is here

View solution in original post

0 Kudos
3 Replies
IvanBespalov
Occasional Contributor III
<?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">    <s:layout>   <s:VerticalLayout gap="10"         paddingBottom="10"         paddingLeft="10"         paddingRight="10"         paddingTop="10" />  </s:layout>   <fx:Script>   <![CDATA[    import mx.utils.StringUtil;    protected function onAddTimeClick(event:MouseEvent):void    {     var now:Date = new Date();     addTextToSparkComponent(now.toString());     addTextToMxComponent(now.toString());    }        private function addTextToSparkComponent(message:String):void    {     txtSpark.text = txtSpark.text.length > 0 ? StringUtil.substitute("{0}\n", txtSpark.text) : "";     txtSpark.text = StringUtil.substitute("{0}{1}", txtSpark.text, message);    }        private function addTextToMxComponent(message:String):void    {     while (message.search("\n") != -1) {      message = message.replace("\n", "<br>");     }     txtMx.htmlText = txtMx.text.length > 0 ? StringUtil.substitute("{0}<br>", txtMx.htmlText) : "";     txtMx.htmlText = StringUtil.substitute("{0}{1}", txtMx.htmlText, message);    }     protected function onAddInputClick(event:MouseEvent):void    {     var inputText:String = txtInput.text;     addTextToSparkComponent(inputText);     addTextToMxComponent(inputText);         }    ]]>  </fx:Script>     <s:Panel title="Inputs"     width="100%">      <s:VGroup width="100%"       height="100%"       gap="10"       paddingLeft="10"       paddingTop="10"       paddingBottom="10">           <s:Button label="Add now time"         click="onAddTimeClick(event)"/>        <s:Label text="Input smthing. Use 'ENTER' to make your text multiline." />        <s:TextArea id="txtInput" />        <s:Button label="Add inputs"         click="onAddInputClick(event)"/>       </s:VGroup>     </s:Panel>    <s:Panel title="Outputs"     width="100%"     height="100%">      <s:HGroup width="100%"       height="100%"       paddingLeft="10"       paddingTop="10"       paddingBottom="10">        <s:VGroup width="100%"        height="100%">          <s:Label text="mx.controls.RichTextEditor" />          <mx:RichTextEditor id="txtMx"             width="100%"            height="100%"            showControlBar="false"/>         </s:VGroup>        <s:VGroup width="100%"        height="100%">          <s:Label text="spark.components.RichTextEditor" />          <s:RichEditableText id="txtSpark"          width="100%"          height="100%" />         </s:VGroup>       </s:HGroup>       </s:Panel>   </s:Application>


P.S. SDK 4.9.0
P.S.2 It's not ArcGIS Flex API question, don't you think? Adobe learning is here
0 Kudos
ShaningYu
Frequent Contributor
Thanks for your response.  I tested your code.  It helps to add <br> on the line.  But when it is used in clickboard, it does not make lines.  E.g. the result is like that:
<br><br>1443333.3333333333<br>370840<br>1443333.3333333333<br>370840
Still be the same line.
It is true that it not a GIS problem.
0 Kudos
IvanBespalov
Occasional Contributor III
Create own utility class, and convert string as you need.
package your.package.name
{
 public class MyHelperClass
 {
  public static function convertToHtml(str:String):String
  {
   if (str != null)
   {
    while (str.search("\n") != -1) {
     str = str.replace("\n", "<br>");
    }
   }
   
   return str;
  }
  
  public static function convertFromHtml(str:String):String
  {
   if (str != null)
   {
    while (str.search("<br>") != -1) {
     str = str.replace("<br>", "\n");
    }
   }
   
   return str;
  }
 }
}


when needed just call
var someString:String = "Acura,<br>Buick,<br>Corvette,<br>Dodge";
var result:String = MyHelperClass.convertFromHtml(someString);
0 Kudos