<s:TextArea id="txt" x="185" y="122" textFlow="{TextConverter.importToFlow(str, TextConverter.TEXT_FIELD_HTML_FORMAT)}">
</s:TextArea>
如果你寫在<fx:Script>就這樣寫吧:
txt.textFlow=TextConverter.importToFlow(str, TextConverter.TEXT_FIELD_HTML_FORMAT)
這里的txt是textArea控件的實例名稱,str就是一個關於htmlText的字符了;
好了下面就給個完整的代碼:
<?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="init()">
<s:TextArea id="txt" x="157" y="118" />
<s:Button id="btn" x="360" y="334" label="發送"/>
<s:TextInput id="input" x="167" y="332"/>
<fx:Script>
<![CDATA[
import flashx.textLayout.conversion.TextConverter;
[Bindable]
private var str:String;
private function init():void
{
btn.addEventListener(MouseEvent.CLICK,doclick);
}
private function doclick(e:MouseEvent):void
{
str="<font color='#ff0000' size='25' face='宋體'>"+input.text+"</font>"
txt.textFlow=TextConverter.importToFlow(str, TextConverter.TEXT_FIELD_HTML_FORMAT)
}
]]>
</fx:Script>
</s:Application>