Return to Snippet

Revision: 30886
at August 24, 2010 20:05 by adrianparr


Updated Code
import flash.text.StyleSheet;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;

var myHTMLText:String = "<span class='defaultStyle'><h1><b>HTML</b> Text <i>(sample <u>header</u>)</i></h1>Here is some <em>sample</em> <strong>html text</strong> "+"filling a text box <a href='http://www.adrianparr.com'>this link to adrianparr.com</a> and example headers"+"<br><br><br><h1>Header h1</h1><h2>Header h2</h2><br><br><br>Hello world<br><br><br><redText>This text <i>will be red</i></redText><br><br><h1>Boo</h1></span>";

var defaultStyleObj:Object = new Object();
defaultStyleObj.fontFamily = "Verdana";

var myStyleSheet:StyleSheet = new StyleSheet();
myStyleSheet.setStyle("body", {fontSize:'15',color:'#000066'});
myStyleSheet.setStyle("h1", {fontSize:'32',color:'#000000'});
myStyleSheet.setStyle("h2", {fontSize:'19',color:'#000000'});
myStyleSheet.setStyle("a:link", {color:'#0000CC',textDecoration:'none'});
myStyleSheet.setStyle("a:hover", {color:'#0000FF',textDecoration:'underline'});
myStyleSheet.setStyle("b", {fontWeight:'bold'});
myStyleSheet.setStyle("em", {fontWeight:'bold'});
myStyleSheet.setStyle(".defaultStyle", defaultStyleObj);
myStyleSheet.setStyle("redText", {color:'#FF0000'});

var myTextField:TextField = new TextField();
myTextField.width = 500;
myTextField.multiline = true;
myTextField.styleSheet = myStyleSheet;
myTextField.htmlText = myHTMLText;
myTextField.autoSize = TextFieldAutoSize.LEFT;
myTextField.wordWrap = true;
myTextField.border = true;
addChild(myTextField);

Revision: 30885
at August 24, 2010 19:54 by adrianparr


Initial Code
import flash.text.StyleSheet;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;

var myHTMLText:String = "<span class='defaultStyle'><h1><b>HTML</b> Text <i>(sample <u>header</u>)</i></h1>Here is some <em>sample</em> <strong>html text</strong> "+"filling a text box <a href='http://www.adrianparr.com'>this link to adrianparr.com</a> and example headers"+"<br><br><br><h1>Header h1</h1><h2>Header h2</h2><br><br><br>Hello world<br><br><br><redText>This text <i>will be red</i></redText><br><br><h1>Boo</h1></span>";

var defaultStyleObj:Object = new Object();
defaultStyleObj.fontFamily = "Verdana";

var myStyleSheet:StyleSheet = new StyleSheet();
myStyleSheet.setStyle("body", {fontSize:'15',color:'#000066'});
myStyleSheet.setStyle("h1", {fontSize:'32',color:'#000000'});
myStyleSheet.setStyle("h2", {fontSize:'19',color:'#000000'});
myStyleSheet.setStyle("a:link", {color:'#0000CC',textDecoration:'none'});
myStyleSheet.setStyle("a:hover", {color:'#0000FF',textDecoration:'underline'});
myStyleSheet.setStyle("b", {fontWeight:'bold'});
myStyleSheet.setStyle("em", {fontWeight:'bold'});
myStyleSheet.setStyle(".defaultStyle", defaultStyleObj);
myStyleSheet.setStyle("redText", {color:'#FF0000'});

var myTextField:TextField = new TextField();
myTextField.width = 500;
myTextField.styleSheet = myStyleSheet;
myTextField.htmlText = myHTMLText;
myTextField.autoSize = TextFieldAutoSize.LEFT;
myTextField.wordWrap = true;
myTextField.border = true;
addChild(myTextField);

Initial URL

                                

Initial Description

                                

Initial Title
AS3 TextField and StyleSheet Example (created in ActionScript)

Initial Tags
css, style, text

Initial Language
ActionScript 3