Why Flex AS3 TextArea Htmltext changes format on event

This is giving me no sleep, I've added my test application here. Just copy and paste to test the application adds well formatted html text to a text area on clicking 'add' then on clicking 'go' I take this html text out to another Text area and I see the text has changed format where the tags get muddled up.

My end goal is to regex the html text out to another format for another interface. However this muddeling of tags is causing me headaches.

Any solutions to prevent or rectify this would be much appreciated.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()"  xmlns:ns1="com.tree.*">
    <mx:Script>
    <![CDATA[
        private function init():void        {
            originalTA.text='<TEXTFORMAT LEADING="-2">'+ '<P ALIGN="JUSTIFY">'+ '<FONT SIZE="26" COLOR="#9B0000" LETTERSPACING="0" KERNING="0"> some text </FONT> '+ '<FONT SIZE="26" COLOR="#BEBEBE"> some text  </FONT> '+ '<FONT SIZE="26" COLOR="#9B0000" LETTERSPACING="0" KERNING="0"> some text </FONT>'+ '</P>'+ '</TEXTFORMAT>';
        }

        private function add():void {
            viewDTA.htmlText=originalTA.text;
        }

        private function go():void {
            htmlTA.text=viewDTA.htmlText;
        }
    ]]>
    </mx:Script>
    <mx:HBox width="100%" height="100%">
        <mx:Label text="input"/>
        <mx:TextArea id="originalTA" height="100%" width="100%"/>
        <mx:Button label="add" click="add()"/>
        <mx:Label text="view"/>
        <mx:TextArea id="viewDTA" height="100%" width="100%"/>
        <mx:Button label="go" click="go()"/>
    </mx:HBox>
    <mx:HBox width="100%" height="100%">
        <mx:Label text="html"/>
        <mx:TextArea id="htmlTA" height="100%" width="100%"/>
    </mx:HBox>
</mx:Application>

Answers


When you set a value to the TextArea.htmlText property Flex automatically inserts additional HTML markup corresponding to the defaultTextFormat set from the CSS styles.

To get around this behavior, I would create a new component that extends the TextArea component and overrides the set htmlText function to store the original text in a new variable called OriginalHTMLText you can access later to get the original HTML text.

Try using this as a starting point:

package
{
    import mx.controls.TextArea;

    public class HTMLStaticTextArea extends TextArea
    {
        public var OriginalHTMLText:String = "";

        public function HTMLStaticTextArea()
        {
            super();
        }

        override public function set htmlText(value:String):void
        {
            super.htmlText = value;
            OriginalHTMLText = value;
        }
    }
}

Need Your Help

Error with “null” EditText applying to end of URL in Android Studio

java android url search android-edittext

So each time I run the app, type in an ID and hit submit; the end result come outs with null as the ID.

Validating a decimal 3.4 in the XSD schema ^{1,3}(?:\.{1,4})?$

regex xml validation xsd

I need to mount an XSD to validate a decimal number 3.4. The entire piece can have up to 3 characters and the fraction part is not mandatory, but if any, need to have up to 4 characters.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.