TDOT Blog Touchwood Creative

Register | Forgot password?

Author Info

Name
Ben Bishop

Job Title
Senior Interactive Developer



Touchwood is continuing to grow!

We are looking for talented Flex developers to join our Interactive Group. If you have any interest we would love to meet you. Please email your resume to us at:

jobs@touchwoodcreative.com


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.

AttachmentSize
StyleText.zip304.48 KB
© Touchwood Creative 2007 | We use Firefox