Skip to main content
Handycam
Known Participant
Oct 27, 2009 10:12 PM UTC
Question

Is it possible to add paragraphs with actionscript?

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 is closed to new replies. Start a new post to keep the conversation going.

3 replies

Adobe Employee
Oct 28, 2009 3:03 AM UTC

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);

     }

}

Translate
Handycam
HandycamAuthor
Known Participant
Oct 28, 2009 6:42 PM UTC

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

object's ID, but I am confused.

Translate
Handycam
HandycamAuthor
Known Participant
Oct 28, 2009 6:53 PM UTC

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.

Translate