2012-11-15 57 views
0

我有一個帶有textArea的項目渲染器。mx: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> 

所以,你能不能幫我解決嗎?

感謝您的幫助

回答

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> 
+0

OK,但我會喜歡使用用戶選擇(beginSelection和endSelection)並僅在這部分應用樣式。謝謝 – Flex60460

+0

同樣可以應用於用戶選擇的文本的更改屬性。 – user1749053