AS3 Flash CS5 - Using embedded fonts with fontDescription.fontName

1.4k views Asked by At

I have a function that has an optional variable myFont. By default, it's set to myFont:String="Impact". However, when I try to define a different font name by using the function, or even just changing the default font name, I get

TypeError: Error #1009: Cannot access a property or method of a null object reference.

Arial isn't embedded anywhere in my project, so I don't really understand why the compiler is being so fussy about others... :<

Here is the FontDescription -> ElementFormat part of the code:

        fontDescription = new FontDescription();

        fontDescription.fontName=myFont;
        fontDescription.fontWeight=FontWeight.BOLD;
        fontDescription.fontPosture=FontPosture.ITALIC;
        fontDescription.renderingMode=RenderingMode.CFF;

        format = new ElementFormat(fontDescription);

Any clues? I've tried [Embed]ing the font in the document class, embedding it via the Flash IDE...

1

There are 1 answers

0
felipemaia On BEST ANSWER

In my experience, Flash`s font embedding has always been a little tricky. The way I embed my fonts are as follows:

  • Create a dynamic text field on the documents stage outside of the visible area (usually up on the top-left side) for each font and setting (bold, italic, both, etc);
  • Click the embed button on each of these created text fields and make sure I select the characters I'm going to use;

That way, since there's a dynamic text field using that font right on the stage, Flash is forced to embed correctly the fonts.

And, the reason why some fonts don't trigger an error, is that they're available for use by default.