Skip to main content
Damon Edwards
Inspiring
November 30, 2007
Question

Applying StyleSheet to a TextArea component

  • November 30, 2007
  • 10 replies
  • 753 views
I'm finding it not possible to attach a style sheet to a TextArea component with AS3, V3 component... Is there a workaround, maybe accessing the TextAreas' textField..??.
This topic has been closed for replies.

10 replies

Participating Frequently
January 3, 2008
This bug is really unbelievable and a huge embarrassment for Adobe. I don't know how could that slip into the final release. I can't believe nobody noticed you can't style the TextArea. Funny thing is that it does work in Flex, where styleSheet is a property of TextArea directly.

kglad
Community Expert
Community Expert
November 30, 2007
you're welcome.
Damon Edwards
Inspiring
November 30, 2007
Wow, this thing is pretty cool. Thanks kglad.
Inspiring
November 30, 2007
You'll need to roll out your own TextArea to get around the error. Something
like this:

package
{

import fl.core.UIComponent;
import flash.text.TextField;
import flash.text.TextFormat;
import fl.controls.TextArea;

public class StylizedTextArea extends TextArea
{

public function StylizedTextArea()
{
super();
}

protected override function drawTextFormat():void {
// if no style sheet exists, call the super method
if(textField.styleSheet == null){
super.drawTextFormat();
return;
}
// This is where the StyleSheeting error occurs. The TextField class will
// not allow a TextFormat to be applied if a StyleSheet exists
// commenting this block seems to fix the error -- needs more testing
/*
var uiStyles:Object = UIComponent.getStyleDefinition();
var defaultTF:TextFormat = enabled ? uiStyles.defaultTextFormat as
TextFormat : uiStyles.defaultDisabledTextFormat as TextFormat;
textField.setTextFormat(defaultTF);

var tf:TextFormat =
getStyleValue(enabled?"textFormat":"disabledTextFormat") as TextFormat;
if (tf != null) {
textField.setTextFormat(tf);
} else {
tf = defaultTF;
}
textField.defaultTextFormat = tf;
*/

setEmbedFont();
if (_html) { textField.htmlText = _savedHTML; }
}
}

}



kglad
Community Expert
Community Expert
November 30, 2007
you're correct. that does screw-up the scrolling. i don't see a problem with text bunching up, but it doesn't appear the textarea can handle a stylesheet gracefully.

here's a custom component that's supposed to resolve the issue:

http://flashscript.biz/flashas3/CustomTextArea/CustomTextArea.html
Damon Edwards
Inspiring
November 30, 2007
it also disables my list component from scrolling.
Damon Edwards
Inspiring
November 30, 2007
yes, it does work, however, the text doesn't span the entire area, it is all bunched up in the top left corner. Looks like it's no recognizing the size of the component, and thinking it's the default size when you first drag it out...
kglad
Community Expert
Community Expert
November 30, 2007
it should still work. the compiler is just informing you it can't use setTextFormat() (which is an issue internal to the component) on a textfield that has a stylesheet property.

Damon Edwards
Inspiring
November 30, 2007
I tried that,

textArea.textField.styleSheet = myCSS;

and I get Error #2009: This method cannot be used on a text field with a style sheet.
kglad
Community Expert
Community Expert
November 30, 2007
yes. assign a styleSheet property to the textarea's textfield property.