2013-12-18 38 views
0

我正在使用Flex 4 spark TextArea並實現了搜索字段。我用下面的代碼來突出顯示文本區域搜索的文本:更改Flex 4中TextArea的文本選擇顏色以供編程選擇

private function findAndHighlightText():void 
    { 
     var text:String = findTextInput.text; 
     var beginIndex:int = scriptSourceTextArea.text.indexOf(text, m_lastFoundIndex); 
     if (beginIndex == -1 && m_lastFoundIndex > 0) 
     { 
      // We are at the end, search back from the begin 
      Alert.show(resourceManager.getString('groovyresources', 'search.at.end'), 
         resourceManager.getString('groovyresources', 'find')); 
      m_lastFoundIndex = 0; 
      beginIndex = scriptSourceTextArea.text.indexOf(text, m_lastFoundIndex); 
     } 
     if (beginIndex != -1) 
     { 
      var endIndex:int = beginIndex + text.length; 
      m_lastFoundIndex = endIndex; 
      scriptSourceTextArea.selectRange(beginIndex, endIndex); 
      scriptSourceTextArea.scrollToRange(beginIndex); 
     } 
     else 
     { 
      Alert.show(resourceManager.getString('groovyresources', 'search.not.found', [text]), 
         resourceManager.getString('groovyresources', 'find')); 
     } 
    } 

最重要的是對文本區的方法selectRange。這突出顯示了TextArea中的文字,但我想使用不同的顏色。

我可以通過應用CSS樣式focused-text-selection-color(見http://www.kirupa.com/forum/showthread.php?354479-Change-highlight-color-for-text-fields)改變手動選擇的高亮顏色,但這並沒有變化的顏色對於程序的選擇。

更新:顏色不會因程序選擇而改變,因爲TextArea在那時沒有焦點。所以我需要找到不重點的選擇顏色的CSS名稱。

回答

1

有2款影響選定的文本是如何在Flex中強調:

.scriptSourceTextArea { 
     focused-text-selection-color: #788ec5; 
     unfocused-text-selection-color: #7e94cb; 
    } 

一個是專注,另一種是當文本區域不具有焦點。