AS3: Adding styles to a TextField() using a new StyleSheet() object


/ Published in: ActionScript 3
Save to your folder(s)

This doesn't show you how to load an external style sheet but it simulates what would happen if the stylesheet.css had already been loaded. Note! There is no simple way of applying a stylesheet to a TextArea component in Flash CS3


Copy this code and paste it in your HTML
  1. var style:StyleSheet = new StyleSheet();
  2. style.parseCSS("h4{color:#ff0000; fontWeight:bold; fontSize:30;}a:link{text-decoration: none;}a:hover{text-decoration: underline;}");
  3. var ti:TextField = new TextField();
  4. ti.x = 150;
  5. ti.y = 150;
  6. ti.width = 100;
  7. ti.height = 100;
  8. ti.styleSheet = style;
  9. ti.htmlText = "<h4>library</h4>";
  10. ti.htmlText += "<p><a href=\"event:http://www.usc.edu\" target=\"_blank\">science</a></p>";
  11. addChild(ti);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.