AS2 SharedFonts (Datagrid Example) – The Last Stand

Translate original post with Google Translate

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

as2sharedfonts.zip (383)

Sharing one font per swf:

<?xml version="1.0" encoding="iso-8859-1" ?>
<movie width="1" height="1" framerate="12">
    <frame>
        <library>
            <font import="src/ttf/georgia.ttf"/>
        </library>
        <import url="http://www.deja-vue.net/test/shared/swf/fonts/Georgia Gras.swf"></import>
    </frame>
</movie>

 

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

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

var fmt:TextFormat = new TextFormat();
fmt.font = "Georgia";

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 version="1.0" encoding="iso-8859-1" ?>
<movie width="1" height="1" framerate="12">
    <frame>
        <library>
            <font name="dragon" import="src/ttf/Lisas Dragons.ttf" glyphs="My little dragon"/>
        </library>
        <import url="http://www.deja-vue.net/shared/swf/font/lisasDragons.swf"></import>
    </frame>
</movie>

 

We then refer the font as follow:

fmt.font = "dragon";

There are advantages to specify a custom name.

- to import various styles in one go:

<?xml version="1.0" encoding="iso-8859-1" ?>
<movie width="1" height="1" framerate="12">
    <frame>
        <library>
            <font name="Charter" import="src/ct.ttf"/>
            <font name="Charter" import="src/ct__Italic.ttf"/>
            <font name="Charter" import="src/ct__Bold.ttf"/>
            <font name="Charter" import="src/ct__BoldItalic.ttf"/>
        </library>
        <import url="http://www.deja-vue.net/test/charters.swf"></import>
    </frame>
</movie>

 

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

var fmt:TextFormat = new TextFormat();
fmt.font = "Charter";

// Italic
fmt.italic = true;

// Italic and Bold
fmt.italic = true;
fmt.bold = true;

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

<movie width="1" height="1" framerate="12">
    <frame>
        <library>
            <font name="Charter Regular" import="src/charterRegular.ttf"/>
            <font name="Charter Medium" import="src/charterMed.ttf"/>
            <font name="Charter Extended" import="src/charterExtended.ttf"/>
        </library>
        <import url="http://www.deja-vue.net/test/charters.swf"></import>
    </frame>
</movie>

 

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

Personally, I use a batch process, like so:

//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"

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 (Datagrid Example) – The Last Stand”

Leave Comment

(required)

(required)