Jul 10

I recently upgraded to the Flex 4 SDK from Flex 3 to compile my ActionScript files. All was fine, and most of my .as files compiled without a problem, until I tried to embed a font in the file to use with TextField instances with embedded fonts. No matter how I arranged the EMBED meta tag, a TextField instance with embedFonts set to true just wouldn’t display the text at all. It was only after a long process of trial, error and Internet search, that I stumbled across the problem. I was using Flex 4 on my Linux laptop, as opposed to Flex 3 on my Windows PC. In this article from Adobe’s site, one of the Flex team explains that Flex 4 uses a different tag in the compiled SWF code to embed fonts – DefineFont4, as opposed to DefineFont3. The TextField instance just won’t work with the former. Richard Leggett explains the situation well in this post.

Fortunately, it’s easy enough to get around by amending your flex-config.xml file in the frameworks folder of your Flex installation. Just add the following lines just under <compiler>:

<mxml>
<compatibility-version>3</compatibility-version>
</mxml>

After this update, your TextField instances should display embedded fonts without any problem. The downside is, you won’t be able to use any new features in Flex 4, such as FXG image embedding. So, with a little more digging (and eventually finding this forum thread), I discovered a property you can set when embedding font files in your ActionScript. It used to be CFF, but since has ‘helpfully’ been renamed embedAsCFF, which should be set to false for embedding fonts for TextField. So, embedding your font as follows allows you to keep your compatibility version as 4+, and not worry about invisible text in TextField instances:

[Embed(source='font.ttf', fontName="font1", mimeType="application/x-font-truetype", embedAsCFF='false')]

In any case, I hope this post helps others from spending lots of time searching for a solution like I did! Incidentally, here is a useful document from Adobe on embedding assets into AS3 files in general.

I’m trying to use Open Source solutions for resource development more and more lately, and most recently switched to Linux (Ubuntu) on my laptop with a view to Flash development with the Flex SDK. Developer Steve Love has an excellent blog post on doing the main setting up here. On Ubuntu, I did get a warning about a FactoryClass not being included, too, although it didn’t seem to affect the final SWF – I did some investigating online, and it turns out you can remedy this by amending another line in the same flex-config.xml file. Locate the line with the setting static-link-runtime-shared- libraries, and make sure that this setting is true rather than false. This does the trick, and ensures that any extra bits and pieces the SWF needs are definitely compiled when mxmlc is run. Strangely, the Flex documentation suggests that this should be set to true by default – mine certainly wasn’t. Here is a comprehensive list of the whole gamut of settings.

With these problems now sorted (a few dozen cups of coffee later), the laptop is all set for easy Flash development on Ubuntu. Incidentally, I’m using gEdit for writing code at the moment – I’m sure I’ll come across better text editors for this kind of thing as I get used to the new operating system!

Leave a Reply

preload preload preload