Toggling rich text copy and pasting on a Halo TextArea control in Flex

The following example shows how you can toggle rich text copy/pasting on a Halo TextArea control in Flex by setting the internal TextField object’s Boolean useRichTextClipboard property.

Full code after the jump.

Since this example uses the mx_internal namespace, you can't always depend on this behavior to work in future versions of the Flex SDK. Use at your own risk.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/08/26/toggling-rich-text-copy-and-pasting-on-a-halo-textarea-control-in-flex/ -->
<mx:Application name="TextArea_getTextField_useRichTextClipboard_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="horizontal"
        verticalAlign="middle"
        backgroundColor="white">
 
    <mx:Script>
        <![CDATA[
            protected function checkBox_change(evt:Event):void {
                var txtField:TextField = txtArea.mx_internal::getTextField();
                txtField.useRichTextClipboard = checkBox.selected;
            }
        ]]>
    </mx:Script>
 
    <mx:ApplicationControlBar dock="true">
        <mx:CheckBox id="checkBox"
                label="useRichTextClipboard"
                selected="true"
                change="checkBox_change(event);"/>
    </mx:ApplicationControlBar>
 
    <mx:TextArea id="txtArea"
            width="240" height="160">
        <mx:htmlText>
            <![CDATA[The <i>quick</i> brown <a href="#">Fox jumps over</a> the <b>lazy</b> dog.]]>
        </mx:htmlText>
    </mx:TextArea>
 
    <mx:TextArea id="debug"
            text="{txtArea.htmlText}"
            width="{txtArea.width}" height="{txtArea.height}" />
 
</mx:Application>

View source is enabled in the following example.