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 External CSS

09.14.2010
| 1907 views |
  • submit to reddit
        // Load external text to populate the TextField and style with external CSS file


/*
 www.tournasdimitrios1.wordpress.com

*/

//First create a dynamic TextField on stage with an instance name "external_txt"

//
var textLoader:URLLoader = new URLLoader();
var textReq:URLRequest = new URLRequest("externalHtmlText.txt");
var cssLoader:URLLoader = new URLLoader();
var cssRequest:URLRequest = new URLRequest("externalCSSText.css");

var customStyle:StyleSheet = new StyleSheet();

function textLoaded(evt:Event):void {
        textLoader.removeEventListener(Event.COMPLETE , textLoaded);	
	cssLoader.load("cssRequest");
	cssLoader.addEventListener(Event.COMPLETE , cssLoaded);
	}
function cssLoaded(evt:Event):void {
        cssLoader.removeEventListener(Event.COMPLETE , cssLoaded);
	customStyle.parseCSS(cssLoader.data);
	external_txt.styleSheet = customStyle;
	external_txt.htmlText = textLoader.data;
}
 textLoader.load(textReq);
 textLoader.addEventListener(Event.COMPLETE , textLoaded);