Subscribe to RSS
get email updates
home | about | pixDif AIR app | video tutorials
polyGeek.com

Register for 360Flex in DC using the ad below and you will automatically be entered in a drawing for a free ticket. Read more.
place your ad here

Web Premium





Display HTML text in the Spark TextArea

February 3rd, 2010 . by polygeek

It isn’t immediately obvious how to display HTML text in a Spark TextArea. Back in the MX days we had textArea.htmlText which is pretty easy to use. But no such beast on the Spark version.

With a Spark text component you have to run your HTML text through a multi-dimensional phase-inducer which is handily provided through spark.utils.TextFlowUtil.importFromString( myHTMLtext );

But you don’t send the output of the importFromString method to the textArea.text. No, no, no. That would be toooo easy. With Spark there’s a new thingy called textFlow. That’s what gets the output of the importFromString() method.

Here’s a very simple example

myTextArea.textFlow = spark.utils.TextFlowUtil.importFromString(
		'some <span fontWeight="bold">bold</span> text.' );

You can use the app below if you want to play around with this and see what’s possible.

view source

There are a few issues that I’ve found with the new Spark Text components. First, I cannot get embeded <span> tags to render. For instance I can’t change the fontWeight to bold and also change the fontSize to, say, 16 on the same text. I’m not sure what’s up with that.

Also, I cannot get unordered-lists to display at all. Perhaps these are just issues that will be resolved when Flex4 is ready for primetime. If you know anything about this I’d love to read about it in the comments.

One interesting bonus I found is that creating a link automatically turns the text blue and underlines it. I’m not sure how you would override that but it’s nice that it doesn’t show up as just regular un-formatted text.

What’s funny is that starting out this was just going to be a simple example with two text fields where you could type in your HTML and then see it rendered below. Then I thought I’d add a button to make the selected text bold. And then italic. And on and on. Sometimes I just don’t know when to quit.

More examples at  Setting text in a Spark RichText control in Flex 4 at blog.FlexExamples.com.

Setting text in a Spark RichText control in Flex 4

If something here has proved valuable to you then feel free to drop a couple of bucks in the tip-jar.

Post to Twitter Post to Delicious Post to Facebook Post to Reddit Post to StumbleUpon


similar posts

4 Responses to “Display HTML text in the Spark TextArea”


comment number 1 by: Paul Robertson

You asked about creating an "unordered list" in the Flex 4 TextArea. I assume you mean you want a bullet list? If so, the answer is "you can't" (TM)

All the Flex 4 text components are based on TLF, and TLF doesn't (yet) support bullet lists.

comment number 2 by: polygeek

@Paul, Thanks man. Now I can stop banging my head trying to do it. I was guessing that it was something that just wasn’t yet implemented. And yes, I was talking about bulleted lists.

comment number 3 by: NOche

The final version of Flex 4 is out and still no way to display <ul><li>…</li></ul>
WTF ?
It was so easy to display in Flex 3, it looks like unfinished job :(

Did you find a way to do this ?

Thaks

comment number 4 by: polyGeek

I haven't found a way to do this. Have you tried using the character codes for bullets and such? That might work. Flex 4 definitely makes a lot of changes to how HTML text is rendered. You could always just use the Flex 3 TextArea to display HTML text in your Flex 4 projects.

   Welcome back (Change)

Leave a Reply

comment feed RSS   subscribe to this comment thread

Recent Posts

   



polyGeek.com

© Copyright 2008 polyGeek.com / Dan Florio, All Rights Reserved Except Where Explicitly Stated
Web Developement Blogs - Blog Catalog Blog Directory
M2 Websites
Local Directory for Los Angeles, CA

Better Tag Cloud