AS2: Inline CSS

This shows how to create Cascading Style Sheets using ActionScript.

/**************************
CSS Translation of Properties
**************************/
/*
HTML				ActionScript
color				color
display				display
font-family			fontFamily
font-size			fontSize
font-weight			fontWeight
margin-left			marginLeft
margin-right		marginRight
text-align			textAlign
text-decoration		textDecoration
*/

//A. Create a new Style Sheet
var ss = new TextField.StyleSheet();
ss.setStyle(".headline", {color:"#FFCCCC", fontSize:"18px"});
ss.setStyle("p", {color:"#666666", fontSize:"14px"});

//B. Create Some Strings
var headline:String = "<span class='headline'>Header 1</span><br>";
var p:String = "<p>lorem ipsum.....</p>";

//C. Create a Dynamic Text Field
var text_txt:TextField = this.createTextField("text_txt", this.getNextHighestDepth(), 0, 0, 100, 50);
text_txt.multiline = true;
text_txt.wordWrap = true;
text_txt.styleSheet = ss;

//D. Load
text_txt.htmlText = headline + p;


/**************************
Undocumente but Useful
**************************/
//Code to Transfer CSS styles to TextFormat
var textStyle:Object = ss.getStyle(".headline");
var tf:TextFormat = ss.transform(textStyle);