We Recommend

Essential ActionScript 3.0 Essential ActionScript 3.0
The book focuses on the core language and object-oriented programming, but also adds a deep look at the centerpiece of Flash Player's new API: display programming. Enjoy hundreds of brand new pages covering exciting new language features, such as the DOM-based event architecture, E4X, and namespaces--all brimming with real-world sample code.


Posted By

chrisaiv on 11/08/07


Tagged

stylesheets styles


Versions (?)


Who likes this?

3 people have marked this snippet as a favorite

copyleft
Akuma99
outbox


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


Published in: ActionScript 3 


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.