AS2 SharedFonts (Datagrid Example) - The Last Stand
Let’s sum up the many faces of sharedfonts with swfmill.
Sharing one font per swf:
<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:
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:
<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:
There are advantages to specify a custom name.
- to import various styles in one go:
<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:
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:
<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:
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!






11 Responses to “AS2 SharedFonts (Datagrid Example) - The Last Stand”
By Tom Lee on 2006-06-15 | Reply
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?
By Mike on 2006-06-15 | Reply
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).
I guess it depends on how you implement CellRenderers on each columns.
If I remember well, last time I checked I still wasn't possible. You can only use one embedded font per Textfield.
By Tom Lee on 2006-06-16 | Reply
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?
By Mike on 2006-06-16 | Reply
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.
By Tom Lee on 2006-06-16 | Reply
Swfmill would definitely streamline the process. Thanks!
By Tom Lee on 2006-06-16 | Reply
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.
By Marcelo de Moraes Serpa on 2006-06-27 | Reply
The listbox "up" and "down" buttons are upside down!
By Nils Millahn on 2006-07-05 | Reply
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.
By Nils Millahn on 2006-07-05 | Reply
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.
By Tim on 2008-12-17 | Reply
This is an extremely useful hack - thanks very much for publishing it! However, I'm slightly concerned about deploying a solution based on this to a client because of the way it works. What I don't understand is - how come the recursive importing of the same swf into itself doesn't throw Flash Player into an infinite loop or cause a memory leak? I understand that the swf gets cached so we don't need to wait for it to load, but still, you would expect Flash Player to try to load it an infinite number of times as each copy that gets imported tries to import itself again.
Can anyone shed any light on this? Does anyone know if there's any versions of Flash Player or browsers that cause problems with this method? Has anyone deployed this on a major website before and had no problems/problems?