6 Replies Latest reply on May 17, 2007 2:56 PM by dan.fox

    Embedding fonts in AS3 with absolute paths

    opticaldrift
      I'm having difficulty embedding fonts in AS3. For instance, using absolute paths:

      [Embed(source="C:\WINDOWS\Fonts\CONSOLA.TTF", fontName="Consolas", mimeType="application/x-font-truetype")]

      ... I get the error message: "Error: unable to resolve 'C:WINDOWSFontsCONSOLA.TTF' for transcoding.

      I'm hoping the backslashes are missing from the error just because the compiler doesn't return them, and not that it's losing them. I've tried various TTFs with the same result. Even tried copying code from the AS3 Cookbook letter for letter. :) Thoughts?
        • 1. Re: Embedding fonts in AS3 with absolute paths
          Level 7
          The backslash is the escape character. To use backslashes in your string
          literal, you would need to escape them:

          "C:\\WINDOWS\\Fonts\\CONSOLA.TTF"


          • 2. Re: Embedding fonts in AS3 with absolute paths
            opticaldrift Level 1
            Duh, that works. I had tried escaping, as well, but I think I may have mistyped the font name I had been testing. Thanks!
            • 3. Re: Embedding fonts in AS3 with absolute paths
              peterent Level 2
              Just to add my 2 cents here: I would copy the font into the project folder and reference it from there. That has the advantage of being able to move the project from person to person (in case some future person has to work on the project and they don't have the font loaded on their computer). Plus you should be able to check the font into a source code control system.

              Oh, and make sure you have the copyright permission to use the font from the font's owner/producer.
              • 4. Re: Embedding fonts in AS3 with absolute paths
                opticaldrift Level 1
                Thanks, peterent. Keeping that font around makes sense, since I suppose then the embed code will use the path to the font. I assume this means you can embed with relative fonts, for cross-machine compatibility at the project level?

                I'm using free and open source pixel fonts. There are actually quite a lot out there, many even specifically designed for Flash/Flex apps, so I may do a roundup. I'm hoping we see more of these in the future; for this kind of work having open fonts becomes really essential.
                • 5. Re: Embedding fonts in AS3 with absolute paths
                  RandyHowk
                  I wrote a class to construct a menu and embedded fonts in that class but when I try to call that class I get a "contains invalid data." if I don't embed the fonts then the class works. I am also embedding the font in main document and the text on the main page works fine. would be glad to post the code if that is supported here.
                  • 6. Re: Embedding fonts in AS3 with absolute paths
                    dan.fox
                    I have a similar issue happening. I am using AS3 and have this code in my file:

                    ////////////////////////////////////////////////////////////////

                    // package, import statements etc...

                    // the line below is the problematic line
                    [Embed(systemFont="..\\..\\..\\fonts\\arial.ttf", fontName="Arial (True Type)", mimeType="application/x-font-truetype")]

                    // now declare my class
                    public class ImageRotator extends UIComponent
                    {

                    // etc.

                    ////////////////////////////////////////////////////////////////

                    The class compiles fine but when I try to run it I get the following runtime error:

                    "Error: Error #2136: The SWF file file:///C:/projects/photogallery_screensaver/bin/photogallery_screensaver.swf contains invalid data."

                    I've tried several things including changing the location of the font file, using a different font file, embedding a systemFont. But I always get the same error.

                    Help please!

                    Thanks,

                    Dan