package {
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.StyleSheet;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
public class CSSFormattingExample extends Sprite {
var loader:URLLoader;
var field:TextField;
var exampleText:String = "<h1>This is a headline</h1>" +
"<p>This is a line of text. <span class='bluetext'>" +
"This line of text is colored blue.</span></p>";
public function CSSFormattingExample():void {
field = new TextField();
field.width=300;
field.autoSize=TextFieldAutoSize.LEFT;
field.wordWrap=true;
addChild(field);
var req:URLRequest=new URLRequest("example.css");
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onCSSFileLoaded);
loader.load(req);
}
public function onCSSFileLoaded(event:Event):void {
var sheet:StyleSheet = new StyleSheet();
sheet.parseCSS(loader.data);
field.styleSheet=sheet;
field.htmlText=exampleText;
}
}
}
// THE 'example.css' FILE SHOULD LOOK LIKE THIS ...
//p {
// font-family: Times New Roman, Times, _serif;
// font-size: 14;
//}
//
//h1 {
// font-family: Arial, Helvetica, _sans;
// font-size: 20;
// font-weight: bold;
//}
//
//.bluetext {
// color: #0000CC;
//}