Revision: 26014
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at April 16, 2010 03:55 by adrianparr
Initial Code
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; //}
Initial URL
http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000232.html
Initial Description
Initial Title
AS3 Loading and Using an External CSS File
Initial Tags
css, format, text
Initial Language
ActionScript 3