Updated: September 28th, 2009

Archive for September, 2009

Runtime Font Publisher; A Flash CS4 Extension.

iconSeptember 28th, 2009 icon10 Comments

Recently, I created my first Flash CS4 extension. The Runtime Font Publisher extension makes it easy to create, configure, and publish SWFs that contain fonts for runtime sharing. Each SWF that is created by the Runtime Font Publisher can contain a single font definition, or multiple definitions. For each font definition it is possible to configure the font name, font source file, font family, font style, and embedded character sets.

Runtime Font Publisher

How-to use

Using a font SWF published from the Runtime Font Publisher is as easy as using the loader class to load the SWF and then updating the textformat object of a textfield to use a font name chosen in the Runtime Font Publisher. SWFs published by the extension will automatically register the fonts with the Flash Player when loaded.

As a simplified example, the following code loads the font SWF that contains the embedded fonts.var loader:Loader = new Loader();
var request:URLRequest = new URLRequest('RSFont.swf');
loader.load(request);
loader.contentLoaderInfo.addEventListener(Event.INIT, onInit);
The Event.INIT handler then updates the textformat object of a textfield on the stage to match the font name of a font embedded in the font SWF. function onInit(event:Event):void {
//embedFonts must be set to true to display a runtime shared font.
textField.embedFonts = true;
var textFormat:TextFormat = textField.getTextFormat();
textFormat.font = "MyFont"; //MyFont is defined in the Font name field.
textField.defaultTextFormat = textFormat;
textField.text = "Some Text";
}

Known issues

Issues know to cause compiler errors include selecting a non-TrueType font for the Family, or selecting style properties incompatible with a specific font file. As the Family drop-down lists all device fonts on a system, selecting a font that is not a TrueType font will cause a compiler error. To quickly determine if a font in the Family drop-down is TrueType or OpenType (indicated by icon), select a textfield and view the Family drop-down in the Flash CS4 properties panel. The font SWFs use the [Embed] tag to embed the fonts. Adobe has a good tutorial on how to embed fonts as metadata. Understanding the details of Adobe’s article will make it easier to debug any compiler errors.

Further troubleshooting can be accomplished by viewing the source files the extension generates. Source files are saved into the \Documents and Settings\{username}\Local Settings\Application Data\Adobe\Flash CS4\en\Configuration\Commands\RSFont\src folder on a PC, and /{username}/Library/Application Support/Adobe/Flash CS4/en/Configuration/Commands/RSFont/src folder on a Mac.

Selecting “All” within the Ranges list often results in SWFs that don’t include any font outlines. No compiler errors are thrown and it’s only obvious by the extremely small file size of the output SWF. Compiling the source with the command line against the 3.2.0 Flex SDK yields success. Could be an issue with the Flash CS4 IDE.

Download

Download the Runtime Font Publisher directly from my site. Please let me know what you think. I have ideas for more features, and I’d love to get more feedback. This extension will be submitted to the Adobe Exchange.

The Author

Johannes Tacskovics
ECMAScript Developer

Portrait of Johannes Tacskovics

On front-end software engineering this is the blog of Johannes Tacskovics, a Los Angeles based ECMAScript Developer. This blog is focused on object oriented software development for the web.

Article Categories

Article Archives

Meta