AS3: Adding text styles to a TextField() using a new Object()


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

There's a way to add styles to text without using the traditional StyleSheet() object. I tend to think of this as a quick and dirty solution


Copy this code and paste it in your HTML
  1. //Create an style that would simulate <h4> tags
  2. var h4:Object = new Object();
  3. h4.fontWeight = "bold";
  4. h4.color = "#FF0000";
  5. h4.fontSize = 30;
  6. //Create a Style to simulate a:link tags
  7. var a:Object = new Object();
  8. a.color = "#00FF00";
  9. a.fontSize = 25;
  10. var aHover:Object = new Object();
  11. aHover.fontSize = 25;
  12. aHover.color = "#cccccc";
  13.  
  14. var style:StyleSheet = new StyleSheet();
  15. style.setStyle("h4", h4);
  16. style.setStyle("a", a);
  17. style.setStyle("a:hover", aHover);
  18.  
  19. var tf:TextField = new TextField();
  20. tf.x = 150;
  21. tf.y = 150;
  22. tf.width = 100;
  23. tf.height = 100;
  24. tf.styleSheet = style;
  25. tf.htmlText = "<h4>library</h4>";
  26. tf.htmlText += "<p><a href=\"event:http://www.usc.edu\" target=\"_blank\">science</a></p>";
  27. addChild(tf);

URL: http://www.adobe.com/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000908.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.