DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Formating The CS3 TextField With Internal CSS
// Create a TextField dynamicaly and style it with internal CSS style-sheet
/*
www.tournasdimitrios1.wordpress.com
*/
var url:String = "text.txt";
var req:URLRequest = new URLRequest(url);
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE ,textLoaded);
loader.load(req);
function textLoaded(evt:Event):void{
trace("Text was loaded");
//textBox.htmlText = loader.data;
textBox.htmlText = evt.target.data; //same as above
textBox.styleSheet = customStyle;
}
//ActionScript 3.0 Language and Components Reference
//Class StyleSheet --> to see all options for CSS
var customStyle:StyleSheet = new StyleSheet();
customStyle.setStyle("a" ,{color:"#CC0000"});
//Create the textFormater
var format:TextFormat = new TextFormat();
format.size = 23;
format.color = 0x000000;
//Create a TextField with Actionscript
var textBox:TextField = new TextField();
textBox.wordWrap = true;//this option <b>must</b> be enabled so that html will corect displayed
//
textBox.border = true;
textBox.borderColor = 0xff0000;
textBox.width = 200;
textBox.defaultTextFormat = format;
textBox.selectable = false;
textBox.multiline = true;
textBox.height = 200;
addChild(textBox);





