Good news: Flex 2.0.1 now supports CSS styling within textArea components, so the following workaround is no longer needed. I'll keep this article posted for posterity. -- Rob
The Flex 2 TextArea control won't currently let you apply a CSS stylesheet to it to format its HTML text content. Here's a workaround you can use for now until there's a more official solution.
If you try to set the styleSheet
property of a standard TextArea control you get runtime error #2009: "This method cannot be used on a text field with a style sheet." That effectively prevents you from styling the HTML in a TextArea control.
You could of course apply a CSS stylesheet to a standard ActionScript 3.0 TextField (flash.text.TextField), but to make that work in Flex 2 you would have to build your own component and manage text scrolling yourself. That's not a task for the meek.
This workaround gives you the convenience of using a standard Flex TextArea plus the ability to style up its contents using CSS.