Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Working with Text and Strings > Formatting text with Cascading Style Sheet styles > Applying a style sheet to a TextArea component | |||
To apply a style sheet to a TextArea component, you create a style sheet object and assign it HTML styles using the TextField.StyleSheet class. You then assign the style sheet to the TextArea component's styleSheet property.
The following examples create a style sheet object, styles, and assign it to the myTextArea component instance.
// Create a new style sheet object and set styles for it.
var styles:TextField.StyleSheet = new TextField.StyleSheet();
styles.setStyle("html", {fontFamily:'Arial,Helvetica,sans-serif',
fontSize:'12px',
color:'#0000FF'});
styles.setStyle("body", {color:'#00CCFF',
textDecoration:'underline'});
styles.setStyle("h1",{fontFamily:'Arial,Helvetica,sans-serif',
fontSize:'24px',
color:'#006600'});
/* Assign the style sheet object to myTextArea component. Set html property to true, set styleSheet property to the style sheet object. */
myTextArea.styleSheet = styles;
myTextArea.html = true;
var myVars:LoadVars = new LoadVars();
// Define onData handler and load text to be displayed.
myVars.onData = function(myStr:String):Void {
if (myStr != undefined) {
myTextArea.text = myStr;
} else {
trace("Unable to load text file.");
}
};
myVars.load("http://www.helpexamples.com/flash/myText.htm");
The preceding block of code creates a new TextField.StyleSheet instance that defines three styles: for the html, body, and h1 HTML tags. Next, the style sheet object is applied to the TextArea component and HTML formatting is enabled. The remaining ActionScript defines a LoadVars object that loads an external HTML file and populates the text area with the loaded text.
Flash CS3
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000913.html
Comments
No screen name said on Feb 4, 2008 at 10:14 AM :