428 Working with Text and Strings
3. Add the following ActionScript to Frame 1 of the main Timeline:
// 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.
4. Select Control > Test Movie to test the Flash document.