Friday, April 17, 2009

Styling text within Flex 3 TextArea using external CSS file

If you ever wondered how to use external style-sheets within a Flex 3 TextArea control to format text here's a nice solution.

example application
source

Embed your textfield styles in flex-applications css file
Application {
fontFamily: embeddedFont;
styleSheet: Embed(source="textFieldStyles.css", mimeType="application/octet-stream");
}
Create StyleSheet from style-definition and assign it and your data to the TextArea instance
private function applicationComplete():void {
textArea.styleSheet =
StyleSheetUtil.forClassDefinition(getStyle("styleSheet"));
textArea.htmlText = data;
}

2 comments:

  1. Hey Joachim...
    thats interesting. Does this work only with flex or also with "normal" flahs as3? Do you have an example for the first part of code in as non-flex code?
    Thx. V.

    ReplyDelete