Flex中实现对一个text渲染不同的字体颜色示例
程序员文章站
2022-03-07 18:41:55
开始把控件局限在label上,发现实现起来似乎不太现实。应该用textarea控件: 复制代码 代码如下:
开始把控件局限在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>