4 Replies Latest reply on Oct 29, 2009 11:14 PM by GordonSmith

    Dynamically add paragraphs to rich text object?

    Handycam Level 1

      If I have an object like

      <s:RichText id="foo">
      <s:content></s:content>
      </s:RichText>
      
      

      Can I manually add paragraphs to it with actionscript?

       

      I want to manually create a new paragraph, assign a string to it, and then stash it in the RichText object.  So I can use a loop to create as many paragraphs as I might need.

       

      I have already done

      comp.promptHead.text = dataList[stepNum].stepTitle
      comp.prompt.text = dataList[stepNum]..prompt;
      

      where the target is:

      <s:RichText color="0xef6c1d" fontFamily="Arial" fontSize="19">
      <s:content><s:span id="promptHead" fontWeight="bold">-</s:span>: <s:span id="prompt">-</s:span></s:content>
      </s:RichText>
      

        • 1. Re: Dynamically add paragraphs to rich text object?
          Peter deHaan Level 4

          @Steve Lombardi,

           

          Not sure if this is the bestest approach, but it should work for you:

           

          <?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/halo">
              <s:controlBarContent>
                  <s:Button click="button1_clickHandler(event);" />
              </s:controlBarContent>
              <fx:Script>
                  <![CDATA[
                      import flash.text.engine.FontWeight;
                      
                      import flashx.textLayout.elements.ParagraphElement;
                      import flashx.textLayout.elements.SpanElement;
                      protected function button1_clickHandler(evt:MouseEvent):void {
                          var span1:SpanElement = new SpanElement();
                          span1.fontWeight = FontWeight.BOLD;
                          span1.text = new Date().toDateString() + ': ';
                          var span2:SpanElement = new SpanElement();
                          span2.text = new Date().toTimeString();
                          var para:ParagraphElement = new ParagraphElement();
                          para.mxmlChildren = [span1, span2];
                          rt.textFlow.addChild(para);
                      }
                  ]]>
              </fx:Script>
              <s:RichText id="rt" color="0xef6c1d" fontFamily="Arial" fontSize="19">
                  <s:textFlow>
                      <s:TextFlow id="tflow"  />
                  </s:textFlow>
              </s:RichText>
          </s:Application>
          

           

          You could also try asking the TLF experts over the TLF forums; http://forums.adobe.com/community/opensource/tlf

           

          Peter

           

          Message was edited by: Peter deHaan (Adobe) -- forum ate my quotes.

          • 2. Re: Dynamically add paragraphs to rich text object?
            GordonSmith Level 4

            Steve, you posted the same question to three different forums.When you do that, Adobe people end up answering your question multipile times and possibly ignoring somebody else's single post. Could you wait a reasonable time to see if you get a reply on one forum before posting elsewhere?

             

            Gordon Smith

            Adobe Flex SDK team

            • 3. Re: Dynamically add paragraphs to rich text object?
              Handycam Level 1

              Sorry. Actually, it was just 2, someone here suggested I post it on 

              the TLF forum.

              • 4. Re: Dynamically add paragraphs to rich text object?
                GordonSmith Level 4

                OK, sorry I jumped on you. I'm really glad you're interested in FTE and TLF... I've spent a long long time integrating them into Flex 4.

                 

                Gordon Smith

                Adobe Flex SDK Team