Adding fonts to your SWF with FAMES
Carlos Rovira, author of the excellent Towards Open Source Flash Development, posted a question today on the MTASC mailing list: "Today a collegue asked me how to rotate some text using only OS tools. To rotate text he must embed the font and to do this he must use the Flash IDE... so I responded that he must use Flash IDE to do this task . . . Do you know some alternative method to insert fonts without the need of Flash IDE?"
Yessir, FAMES to the rescue!
1. Create a new project in Eclipse, call it Swfmill Font Test.
2. Create your SWFML file, FontTest.xml:
Note how you can specify only the glyphs you want to use to be embedded.
3. Compile your skeleton swf from the command line, using:
swfmill simple FontTest.xml FontTest.swf
4. Create a new ActionScript file called FontTest.as:
Note how we specify the font name ("kharon") based on the id in our SWFML file. Also note that I had to massage the results getTextExtent() was giving me (if you turn the textfield's border on remove the correction, you'll see why.)
5. Create your Flashout file, FontTest.flashout and set your SWF and root class.
6. Compile to run! You should see the SWF below, using the Kharon4a pixel font by orgdot.
Note: I noticed that Flashout doesn't display the resulting SWF correctly. See snapshow below:
Download the example files (22kb)
[Update] George (from Square Circle) just emailed me to let me know that the text field doesn't completely display on a Mac. Oh gotta love getTextExtent() :) Just alter the CORRECTION_FACTOR constant (raise it) if you get the same issue.I tried using getTextExtent2() but that didn't work. Actually, mx.core.ext.UIObjectExtensions wouldn't run under MTASC. It gave an annoying Local variable redefinition error due to the way the class is coded. That's one compiler error I'm not too fond of (and usually I just love the critters) as it's very convenient to use local vars like i, etc. all over the place and I actually *do* want to think of them as different variables each time I use them.)