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

Kalatravas has posted 29 posts at DZone. View Full User Profile

Formating The CS3 TextField With Internal CSS

  • submit to reddit
        // Create a TextField dynamicaly and style it with internal CSS style-sheet



var url:String = "text.txt";
var req:URLRequest = new URLRequest(url);

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE ,textLoaded);

function textLoaded(evt:Event):void{
	trace("Text was loaded");
	//textBox.htmlText =;  
	textBox.htmlText =;  //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;