Flex textarea stylesheet problems

Recently I had to create an irc chat for flex (Created with as3irclib). Everything worked pretty well, except of these damn stylesheets for textfields.

This is my textarea with a stylesheet, which interprets tags.
chat_style_good

Now clicking into the textarea – e.g. drag the slider or the select something… nothing is changing.
chat_style_bad
After inserting the next message, the font has broken down. Damn stylesheets.

Now here’s the workaround: …

I created a subclass of the textarea and overrode the focus handlers. God bless object orientated programming.

Get it here

	import flash.events.FocusEvent;
	import flash.text.StyleSheet;
 
	import mx.controls.TextArea;
 
	public class StyleTextArea extends TextArea
	{
		public function StyleTextArea()
		{
			super();
		}
 
 
		override protected function focusInHandler(event:FocusEvent) : void
		{
			// do nothing
		}
		override protected function focusOutHandler(event:FocusEvent) : void
		{
			// reset the style
			var ss:StyleSheet = this.styleSheet;
			this.styleSheet = null;
			this.styleSheet = ss;
		}
	}

Everything I did, was, to null the styleSheet property and set it again after the focus was lost. Then everything worked well. Maybe it is not the best solution for this problem, but internet research didn’t got me a better one.

Tags: , , , ,

2 Responses to “Flex textarea stylesheet problems”

  1. Simon says:

    Hi there,

    I was wondering if you are willing to share the source of your flex irc client?

  2. Georg says:

    There is already a more well-engineered version, i think.
    Check this out: http://code.google.com/p/flexircclient/

Leave a Reply