How to Apply a Stylesheet to a Text Component
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 |
