Flex中实现对一个text渲染不同的字体颜色示例
作者:
本文为大家详细介绍下Flex中如何实现对一个text渲染不同的字体颜色,具体的实现思路及代码如下,有兴趣的朋友可以参考下哈,希望对大家有所帮助
开始把控件局限在label上,发现实现起来似乎不太现实。应该用textarea控件:
<?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" minWidth="955" minHeight="600" creationComplete="inital();">
<fx:Script>
<![CDATA[
import flashx.textLayout.conversion.TextConverter;
public function inital():void{
var str:String = "<font color='#ff0000'>123456<font color='#32CD32'>shit</font></font>";
txt.textFlow = TextConverter.importToFlow(str, TextConverter.TEXT_FIELD_HTML_FORMAT);
//txtArea.text = "我是中国人我是中国人我是中国人我是中国人";
}
]]>
</fx:Script>
<mx:Canvas x="300" y="300" width="500" height="500">
<s:TextArea id="txt">
</s:TextArea>
</mx:Canvas>
</s:Application>
复制代码 代码如下:
<?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" minWidth="955" minHeight="600" creationComplete="inital();">
<fx:Script>
<![CDATA[
import flashx.textLayout.conversion.TextConverter;
public function inital():void{
var str:String = "<font color='#ff0000'>123456<font color='#32CD32'>shit</font></font>";
txt.textFlow = TextConverter.importToFlow(str, TextConverter.TEXT_FIELD_HTML_FORMAT);
//txtArea.text = "我是中国人我是中国人我是中国人我是中国人";
}
]]>
</fx:Script>
<mx:Canvas x="300" y="300" width="500" height="500">
<s:TextArea id="txt">
</s:TextArea>
</mx:Canvas>
</s:Application>