mx:TextArea更改文本颜色的一部分

时间:2012-11-15 08:16:57

标签: actionscript-3 flex datagrid flash-builder flashbuilder4

我有一个带有textArea的项呈示器。

    <?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                          xmlns:s="library://ns.adobe.com/flex/spark" 
                          xmlns:mx="library://ns.adobe.com/flex/mx" 
                          focusEnabled="true">

    <fx:Script>
        <![CDATA[
            import mx.controls.DataGrid;
            import mx.controls.dataGridClasses.DataGridColumn;
            import mx.controls.listClasses.BaseListData;
            import mx.core.UITextField;
            public var htmlModif:String;

            /*  protected function lblData_changeHandler(event:Event):void
             {
                 htmlModif=lblData.htmlText;
                 dataGridListData.label = htmlModif;

             } */

            override public function validateProperties():void
            {
                super.validateProperties();
                if (listData)
                {
                    var dg:DataGrid = DataGrid(listData.owner);

                    var column:DataGridColumn = dg.columns[listData.columnIndex];

                    var htmlText:UITextField = lblData.htmlText as UITextField;

                }


            }
        ]]>
    </fx:Script>

    <mx:TextArea id="lblData" top="0" left="0" right="0" bottom="0" 
                 htmlText="{dataGridListData.label}" 
                 wordWrap="true"
                 editable="true"
                 creationComplete="htmlModif=lblData.htmlText"
                 change="htmlModif=lblData.htmlText"/>
</s:MXDataGridItemRenderer>

更改后,我将htmlModif放在arraycollection上以保存新值。

我有些情况下,我喜欢改变部分文字的颜色或风格。 如果更改是关于样式(粗体,斜体......)

,它适用于所有文本
DP_LISTEREDVCLI[ligneIndexEdit].scRub2="<b>"+DP_LISTEREDVCLI[ligneIndexEdit].scRub2+"</b>

但如果改变是关于颜色的话,我就行不通了:

DP_LISTEREDVCLI [ligneIndexEdit] .scRub2 = “” + DP_LISTEREDVCLI [ligneIndexEdit] .scRub2 + “”;

我认为这种干扰是因为在这种情况下新值是这样的:

<FONT COLOR='#FFAE10'> <TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="12" COLOR="#0C1E37" LETTERSPACING="0" KERNING="0">mais pas de disparition</FONT></P></TEXTFORMAT></FONT>

那么,你能帮我解决一下吗?

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

试试这个,我附上了输出的屏幕截图, enter image description here

<?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">


    <fx:Script>
        <![CDATA[
            import mx.collections.*;
            private var DGArray:Array = [
                {Artist:'Pavement 1 ', label:'Slanted and Enchanted', Price:11.99},
                {Artist:'Pavement 2 ', label:'without color <FONT COLOR="#FF00FF"> <TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="12" COLOR="#FF00FF" LETTERSPACING="0" KERNING="0">Slanted and Enchanted</FONT></P></TEXTFORMAT></FONT>', Price:15.99}];

        ]]>
    </fx:Script>

    <mx:DataGrid id="myGrid" width="100%" height="100%" 
                 dataProvider="{DGArray}" itemRenderer="IR" >

    </mx:DataGrid>
</s:Application>

Itemrenderer代码,

<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                          xmlns:s="library://ns.adobe.com/flex/spark" 
                          xmlns:mx="library://ns.adobe.com/flex/mx" 
                          focusEnabled="true">

    <fx:Script>
        <![CDATA[
            import mx.controls.DataGrid;
            import mx.controls.dataGridClasses.DataGridColumn;
            import mx.controls.listClasses.BaseListData;
            import mx.core.UITextField;
            public var htmlModif:String;

            /*  protected function lblData_changeHandler(event:Event):void
            {
            htmlModif=lblData.htmlText;
            dataGridListData.label = htmlModif;

            } */

            override public function validateProperties():void
            {
                super.validateProperties();
                if (listData)
                {
                    var dg:DataGrid = DataGrid(listData.owner);

                    var column:DataGridColumn = dg.columns[listData.columnIndex];

                    var htmlText:UITextField = lblData.htmlText as UITextField;

                }


            }
        ]]>
    </fx:Script>

    <mx:TextArea id="lblData" top="0" left="0" right="0" bottom="0" 
                 htmlText="{dataGridListData.label}" 
                 wordWrap="true"
                 editable="true"
                 creationComplete="htmlModif=lblData.htmlText"
                 change="htmlModif=lblData.htmlText"/>
</s:MXDataGridItemRenderer>