How to Apply a Stylesheet to a Text Component
Submitted by ben.bishop on Fri, 02/27/2009 - 22:42.Problem:
You want to be able to apply a stylesheet to a text component.
Solution:
To solve this problem, we are going to extend the Text component with our own custom text component called "StyleText:"
public class StyleText extends Text
{
private var _styleSheet:StyleSheet = new StyleSheet();
public function get styleSheet():StyleSheet{
return _styleSheet;
}
public function set styleSheet(s:StyleSheet):void{_styleSheet = s;
this.textField.styleSheet = s;}
public function StyleText()
{super();
}
}
Basically, what we end up doing is adding a property called "stylesheet" to the text component. By using a setter function, we can assign the stylesheet to the "textField" property of the original Text component.
Attached to this post is an example project.
| Attachment | Size |
|---|---|
| StyleText.zip | 304.48 KB |
Reply
- Web page addresses and e-mail addresses turn into links automatically.
- Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
- Lines and paragraphs break automatically.
