Updated: September 28th, 2009

Runtime Font Publisher; A Flash CS4 Extension.

iconSeptember 28th, 2009

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.

10 Responses to “Runtime Font Publisher; A Flash CS4 Extension.”

  1. just as i was beginning to go insane with fonts and cs4… thanks buddy

  2. [...] This post was mentioned on Twitter by HowDo.us and Marc Pelland. Marc Pelland said: stumbled across something that could be very useful. thanks johannes http://bit.ly/Ehp09 [...]

  3. [...] This post was Twitted by marteinn_se [...]

  4. Thanks Marc! Good timing on the release of this, just saw your twitter account said you were working on a strategy for loading fonts with CS4. The source my extension generates should give you some ideas.

  5. [...] check it out: http://blog.johannest.com/2009/09/28/runtime-font-publisher-a-flash-cs4-extension/ [...]

  6. [...] Adobe’s documentation, and some of it came from personal experience while developing the Runtime Font Publisher extension. This list was generated out of a desire to see all this information in a single [...]

  7. Hi,
    Thanks for sharing your creation. It seems like a great aid for us. I’m having a heck of a time trying to embed an OpenType font by other means. I have a question about your method:

    If I have already uploaded the swf file generated by your extension by other means (for several reasons I’m using the BulkLoader class for all my uploads), how can I access the font itself?

    Thank you so much

  8. Hi Mauricio,
    Thanks, glad you think the extension will be an aid for you. As for your question. The document class for the SWF that contains the runtime font definitions has logic that registers the fonts embedded in the SWF. BulkLoader can still be used to load the SWF. The font will be ready to access when the SWF has finished loading and the document class has been instantiated. To access the font at runtime, use the name that you specify in the Font name field of the extension.

    The document class also has an array called fonts with a collection of all the fonts that have been embedded within that particular font SWF.

  9. gr8 tool … have been using it since long time, however I have an issue. Is it possible to use two separate fonts (one is regular nad the other bold) to make it work for example with htmlText like this:

    bold en of bold.

    I have not idea how to do it even if i Have the same font but styles are in separate ttf files. Please help.

  10. ok I did it through:

    var styles:StyleSheet = new StyleSheet();
    styles.setStyle(“em”, {
    display:”inline”,
    fontFamily: “FuturaBKBold”,
    fontStyle: “regular”
    });
    tf.styleSheet = styles;

    And it works fine now for <em>Bolded Text</em>

Leave a Reply

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