Posted By

chrisaiv on 01/30/08


Tagged

css as2


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

aaron411
crashdr
mattlohmann


AS2: Inline CSS


 / Published in: ActionScript
 

This shows how to create Cascading Style Sheets using ActionScript

  1. /**************************
  2. CSS Translation of Properties
  3. **************************/
  4. /*
  5. HTML ActionScript
  6. color color
  7. display display
  8. font-family fontFamily
  9. font-size fontSize
  10. font-weight fontWeight
  11. margin-left marginLeft
  12. margin-right marginRight
  13. text-align textAlign
  14. text-decoration textDecoration
  15. */
  16.  
  17. //A. Create a new Style Sheet
  18. var ss = new TextField.StyleSheet();
  19. ss.setStyle(".headline", {color:"#FFCCCC", fontSize:"18px"});
  20. ss.setStyle("p", {color:"#666666", fontSize:"14px"});
  21.  
  22. //B. Create Some Strings
  23. var headline:String = "<span class='headline'>Header 1</span><br>";
  24. var p:String = "<p>lorem ipsum.....</p>";
  25.  
  26. //C. Create a Dynamic Text Field
  27. var text_txt:TextField = this.createTextField("text_txt", this.getNextHighestDepth(), 0, 0, 100, 50);
  28. text_txt.multiline = true;
  29. text_txt.wordWrap = true;
  30. text_txt.styleSheet = ss;
  31.  
  32. //D. Load
  33. text_txt.htmlText = headline + p;
  34.  
  35.  
  36. /**************************
  37. Undocumente but Useful
  38. **************************/
  39. //Code to Transfer CSS styles to TextFormat
  40. var textStyle:Object = ss.getStyle(".headline");
  41. var tf:TextFormat = ss.transform(textStyle);

Report this snippet  

You need to login to post a comment.