2013-06-04 41 views
1
<s:RichEditableText editable="false" styleName="chatWin" height="550" width="100%"> 
     <s:textFlow> 
      <s:TextFlow> 
        <s:p>Inline<s:br />TextFlow</s:p> 
      </s:TextFlow> 
     </s:textFlow> 
</s:RichEditableText> 

我要動態地添加此<s:p>標籤,從而使聊天......我已經試過這樣:如何動態文本和標籤裏面添加的textFlow

var p:p = new p(); 

但這不工作

回答

1

而是內MXML的聲明文本流,你可以通過編程方式追加到一個字符串變量,並與TextConverter.importToFlow()迴流更新文本。

例子:

chat-window

上輸入,從輸入字段文本附加和迴流:

<?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"> 

    <fx:Script> 
     <![CDATA[ 
      import flashx.textLayout.conversion.TextConverter; 
      import flashx.textLayout.elements.TextFlow; 

      import mx.events.FlexEvent; 

      [Bindable] 
      public var text:String = "<p>Inline<br />TextFlow</p>"; 

      protected function input_enterHandler(event:FlexEvent):void 
      { 
       text += input.text; 
       input.text = null; 
      } 
     ]]> 
    </fx:Script> 

    <s:layout> 
     <s:VerticalLayout /> 
    </s:layout> 

    <s:TextInput id="input" 
       enter="input_enterHandler(event)" /> 

    <s:RichEditableText editable="false" 
         selectable="true" 
         textFlow="{TextConverter.importToFlow(text, TextConverter.TEXT_FIELD_HTML_FORMAT)}" 
         buttonMode="true" 
         width="100%" 
         height="100%" /> 

</s:Application> 
+0

很大......... –

+0

我怎樣才能爲HTML設置內聯樣式?因爲我試圖設置樣式=「顏色:紅色」,它不起作用,這是可能的嗎? –

+0

This Works:' RED' –