Posted By

chrisaiv on 11/08/07


Tagged

stylesheet styles as3


Versions (?)

Who likes this?

12 people have marked this snippet as a favorite

copyleft
Akuma99
outbox
abdsign
THEPWN3R
enajenkins
sidneydekoning
mediapoint
TrentSkunk
tspitzr
adrianparr
vdubplate


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


 / Published in: ActionScript 3
 

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

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

  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);

Report this snippet  

You need to login to post a comment.