sparkstrike 2014-04-24
利用RichText动态加载带格式的字符串,如:
<p>The quick brown <span color="#ff0000">fox jumps over</span> the lazy dogg.</p>
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/08/11/setting-text-in-a-spark-richtext-control-in-flex-4/ -->
<s:Application name="Spark_RichText_text_test"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo">
<fx:Script>
<![CDATA[
import spark.utils.TextFlowUtil;
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
var d:String = '<p>The quick brown <span color="#ff0000">fox jumps over</span> the lazy dogg.</p>';
richTxt.textFlow = TextFlowUtil.importFromString(d);
}
]]>
</fx:Script>
<fx:Declarations>
<fx:String id="htmlTextAsMarkup"><![CDATA[<p>The quick brown <span fontWeight="bold">fox jumps over</span> the lazy dogg.</p>]]></fx:String>
</fx:Declarations>
<!-- <s:RichText id="richTxt"
textFlow="{TextFlowUtil.importFromString(htmlTextAsMarkup)}"
horizontalCenter="0" verticalCenter="0" />-->
<s:RichText id="richTxt"
horizontalCenter="0" verticalCenter="0" />
<s:Button x="34" y="32" label="按钮" click="button1_clickHandler(event)"/>
</s:Application>更多选择,请查看链接:http://blog.flexexamples.com/2009/08/11/setting-text-in-a-spark-richtext-control-in-flex-4/