actionscript-3flashembedded-fontsflash-cc

Adobe CC Flash Pro: Proper way to embed and use fonts?


I recently upgraded to Adobe CC from Adobe CS6, and none of my text is showing in my Flash Professional project anymore. It contains a lot of dynamic text and htmlText. I'm not quite sure if I was doing it properly before, as I read several guides that explained different methods, but at least it was working.

I've had some success in trying to fix everything, but I would appreciate it if anyone could tell me the proper way to do it with Adobe CC. Here's how I'm trying to do it now.

  1. Add the font to the library, check the "Export for Actionscript" box, and assign a class name.
  2. Create an instance of the font and the bold and italic versions:

    var myFont:Font = new MyFont();
    var myFontBold:Font = new MyFontBold();
    var myFontItalic:Font = new MyFontItalic();
    
  3. Set up the textFormat:

    var myTextFormat:TextFormat = new TextFormat();
    myTextFormat.font = myFont.fontName;
    
  4. Set up the textField and apply the textFormat:

    var myTextField:TextField = new TextField();
    myTextField.defaultTextFormat = myTextFormat;
    

This will get the text to display, but if I try putting bold or italic tags in my htmlText, neither of them work.

myTextField.htmlText = "This is <b>bold</b>. This is <i>italic</i>.";

Also, do I need to do Font.registerFont anymore? I had that in my previous code, but I was never sure why I needed it.


Solution

  • Try creating and setting a style sheet that assigns the bold and italic versions of the font to the appropriate tags:

    var style:StyleSheet = new StyleSheet();
    style.setStyle("i", {fontFamily: myFontItalic.fontName});
    style.setStyle("b", {fontFamily: myFontBold.fontName});
    
    myTextField.styleSheet = style;
    
    myTextField.htmlText = "This is <b>bold</b>. This is <i>italic</i>.";