Skip to main content
Handycam
Known Participant
October 27, 2009
Question

Is it possible to add paragraphs with actionscript?

  • October 27, 2009
  • 1 reply
  • 663 views

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.

Such as

for each (s:String in myCollection) {

   [ foo add a p element with s in it ]

}

This topic has been closed for replies.

1 reply

Adobe Employee
October 28, 2009

How about something like this?

public function appendToFlow(textFlow:TextFlow, myCollection:Array):void

{

     for each (s:String in myCollection)

     {

          var p:ParagraphElement = new ParagraphElement();

          var span:SpanElement = new SpanElement();

          span.text = s;

          p.replaceChildren(0, 0, span);

          textFlow.replaceChildren(textFlow.numChildren, textFlow.numChildren, p);

     }

}

Handycam
HandycamAuthor
Known Participant
October 28, 2009

What's the "TextFlow" that I pass it? It's obviously not the RichText

object's ID, but I am confused.

Handycam
HandycamAuthor
Known Participant
October 28, 2009

I think I've got it:

var textFlow:TextFlow = new TextFlow(); for each ( var s:String in instructionsArray) {      var p:ParagraphElement = new ParagraphElement();      var span:SpanElement = new SpanElement();      span.text = s;      p.replaceChildren(0, 0, span);      textFlow.replaceChildren(textFlow.numChildren, textFlow.numChildren, p); } instructionText.content = textFlow;

Where "instructionText" is a RichText object.

This is very, very cool, btw.