AS2 SharedFonts

Let’s sum up the many faces of sharedfonts with swfmill.

as2sharedfonts.zip (525)

Sharing one font per swf:

[xml]





[/xml] 

CommandLine :
swfmill simple “src/georgia.xml” “deploy/Georgia Gras.swf”

if we do so, we access the font by its default name:

[as]
var fmt:TextFormat = new TextFormat();
fmt.font = “Georgia”;
[/as]

Because we didn’t give the font any name in particular in the configuration file, the embedded font is identified by its Digital Signature.

In case we want to specify a name:
[xml]





[/xml] 

We then refer the font as follow:

[as]
fmt.font = “dragon”;
[/as]

There are advantages to specify a custom name.

- to import various styles in one go:

[xml]








[/xml] 

We have then free hand to use the style we want:

[as]
var fmt:TextFormat = new TextFormat();
fmt.font = “Charter”;

// Italic
fmt.italic = true;

// Italic and Bold
fmt.italic = true;
fmt.bold = true;
[/as]

- It’s very handy if we deal with differents weights by classifying them semantically:

[xml]






[/xml] 

Finally it’s up to you to decide how to handle the build:

Personally, I use a batch process, like so:

[xml]
//buildFonts.bat
swfmill simple “src/dejavue/cactus.xml” “build/dejavue/cactus.swf”
swfmill simple “src/dejavue/benegraphic.xml” “build/dejavue/Benegraphic.swf”
swfmill simple “src/dejavue/The Dark Crystal.xml” “build/dejavue/The Dark Crystal.swf”
swfmill simple “src/dejavue/Lisas Dragons.xml” “build/dejavue/gs.swf”
swfmill simple “src/dejavue/KingArthurSpecial.xml” “build/dejavue/King Arthur Special.swf”
[/xml]

Okay, that’s all folks!
You will learn more from the source files where you’ll find:

- the TTF/ XML assets’ directory structure inside sharedfontBuilder;) folder.
- the source .as files (Application and TextFormatCellRenderer classes).

——————————————————————————–

A few words about the application example

- Datagrid instantiation and cellRenderer linkage were all done in Fla. ActionScript was injected later with MTASC.

- I used Pixlib‘s XMLToObject and Libstack/GraphicLib to handle the fonts loading process (I LOVE Pixlib, everybody should know from now ^^).

Enjoy!

Pixlib, Shared Font, Swfmill

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

10 Responses to “AS2 SharedFonts”
  • Tom Lee says:

    This is really cool, if I understand it correctly… The fonts are being loaded individually… Are they available for use anywhere in the datagrid, or just in individual cells? Can you do multiple fonts in the same TextField, as with htmlText?

  • Mike says:

    Hi Tom,

    Yes, in this case the fonts are loaded individually.
    Once the Flash Player references them in the library they are globally available (You can use them anywhere).

    Are they available for use anywhere in the datagrid, or just in individual cells?

    I guess it depends on how you implement CellRenderers on each columns.

    Can you do multiple fonts in the same TextField, as with htmlText?

    If I remember well, last time I checked I still wasn’t possible. You can only use one embedded font per Textfield.

  • Tom Lee says:

    I’m not very familiar with swfmill. It looks really cool, but I haven’t had time to dig into it yet. Is it possible to get the same results with the Flash IDE, or does swfmill work around some limitations?

  • Mike says:

    Swfmill is very easy to use. Plus, with the source files I provided you have the necessary bits of code to start very quickly.
    If however you absolutely want to do it using the IDE, you can check the following article: Zárate – Shared Fonts Today. But IMHO its much more complicated that way.

  • Tom Lee says:

    Swfmill would definitely streamline the process. Thanks!

  • Tom Lee says:

    By the way, in my testing I have found that you can in fact use multiple fonts in the same textfield using the shared fonts technique you describe. However, rather than using a TextFormat object to format the TextField, you set TextField.html to true, and set the htmlText like this:

    TextField.htmlText = ‘Foo Bar’;

    Incidentally, I never was able to get the Zarate method to work for me.

  • The listbox “up” and “down” buttons are upside down! :roll:

  • Nils Millahn says:

    I love this technique but can’t get it to work with Flash 8.

    The fonts show up but the text is completely misaligned – moves up by about 20 pixels or so. When I add ‘version=”8″‘ to the XML, no text shows up at all.

    Any suggestions?

    cheers – Nils.

  • Nils Millahn says:

    I’ve tried with another TTF now and the font is aligned correctly.
    Adding ‘version=”8″‘ still results in no fonts being displayed anymore though.

    Anybody else had these problems or resolved them?

    - Nils.

Leave Comment

(required)

(required)


eXTReMe Tracker