Set the font with CSS : StyleSheet « Development « Flash / Flex / ActionScript






Set the font with CSS

 

package{
  import flash.display.Sprite;
  import flash.text.*;
  public class Main extends Sprite{
    public function Main(){
        var styleSheet:StyleSheet = new StyleSheet(  );
        var pStyle:Object = new Object(  );
        pStyle.fontFamily = "fontName";
        styleSheet.setStyle("p", pStyle);
        var t:TextField = new TextField(  );
        t.embedFonts = true;
        t.styleSheet = styleSheet; // Assign styleSheet before assigning htmlText!
        t.htmlText = "<p>hello world</p>";
    }
  }
}

        








Related examples in the same category

1.Text formatted with an external style sheet
2.Load a CSS document and use that data to populate a StyleSheet object
3.Use CSS to in TextField
4.Formatting text with a programmatically created style sheet
5.Formatting applied to a specific class of paragraph