Solved! Go to Solution.
<?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><?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>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;
}
}
}var someString:String = "Acura,<br>Buick,<br>Corvette,<br>Dodge"; var result:String = MyHelperClass.convertFromHtml(someString);