R – Font Embedding in Flexbuilder Vs. CS4

actionscript-3apache-flexflashfonts

I have an all-AS3 Flex project in which I embed fonts. I'm trying to run this project from CS4. However, for some reason the text isn't showing up at all.

The code in the Flex AS3 looks like this:

    [Embed(source='C:/WINDOWS/Fonts/ArialBD.TTF',  fontWeight = 'bold', fontName='ArialBold', unicodeRange='U+0020-U+0020,U+0021-...')] //a bunch of other unicode
    public static var _VerdanaFontBold:Class;  

    [Embed(source='C:/WINDOWS/Fonts/Arial.TTF', fontWeight = 'regular', fontName='Arial', unicodeRange='U+0020-U+0020...')] //a bunch of other unicode
    public static var _VerdanaFont:Class;  

And in constructor of the extended textfield in which my text appears I have:

        Font.registerFont(_VerdanaFontBold);
        Font.registerFont(_VerdanaFont); 

I found this article on embedding metadata with Flash, but I couldn't get that to work either (I tried systemFont="Arial" as well as suggested in the comments at the bottom of that article).

So I tried commenting out the above lines and doing it another way. In CS4, I understand that I'm supposed to create a blank textfield in design mode in the FLA file. I then can select fonts to embed in the properties panel. I selected verdana (upper and lower case, punctuation, number, etc). But again when I run the app in CS4, the textfield is blank.

The fact that I'm embedding the font in a blank textfield, and not the one that's called by the document class I've set, shouldn't matter, right? — the font should just be embedded in the swf and available for use. But it's blank.

Anyone have any ideas?

Best Answer

to embed a font in flash cs4 I would do the following.

  1. in the flash environment, add a font symbol in the library panel. Make sure to click on the "export for actionsctipt button". Note the name of the font class. This will be the name of the font class you will use in your as3 code. Finally click ok and ignore the following warning message.

  2. You can then access this font class from your as3 files. For instance

    import flash.text.Font; ...

    var titleField:TextField = new TextField();

    var myFont:Font = new nameOfFontClass(); // see point 1

    var format:TextFormat = new TextFormat(); format.font = myFont.fontName;

    titleField.defaultTextFormat = format; titleField.embedFonts = true;

hope this helps

Related Topic