Flash & Fonts
Categories: Flash
I’ve written about the pains of fonts in flash before; and it something that still plauges my work today. However, since that post new tools have been created, new workflows introduced, and with that some new findings.
Fonts With SWFMILL
SWFMILL is an awesome tool that may allow you to leave the Flash IDE untouched for some projects. However, embedding fonts seems to be scarcely documented (I had trouble getting the methods documented working). Here are the two links I’ve found that document embedding fonts with swmill:
I wasn’t able to get embedded fonts working using the information above, so here is my method. This is what my swfmill xml looks like.
FontFile.ttf must be referenced relative to the location of the swfml file, and must be a TrueType font for swfmill to read it successfully. If you want to use a non-TrueType font convert it to a TrueType font with a tool such as FontForge (works great and its free, but has a horrific UI).Now if you create a NavButton class that looks something like this:
[code lang=”actionscript”]
class NavButton extends MovieClip {
private var oTitle:TextField;
function NavButton() {
super();
oTitle.selectable = false;
oTitle.multiline = false;
oTitle.wordWrap = false;
oTitle.textColor = 0xFFFFFF;
oTitle.autoSize = true;
oTitle.text = “This is a title”;
}
}
[/code]
And attach the NavButton to the stage using attachMovie()
you should see the text come up. Note: you don’t need to set oTitle.embedFonts = true;
to make this work correctly! Actually, dont use embedFonts
at all!
You may have noticed the properties that I had to set on oTitle
, this will be different for every situation. It seems that swfmill sets a bunch of default properties when creating a textfield. As a reference, here is the output from dumpObject(oTitle)
(dumpObject() is a method from my debug class):
[code]
styleSheet:undefined
mouseWheelEnabled:true
condenseWhite:false
restrict:null
textHeight:48
textWidth:54
bottomScroll:1
length:12
selectable:true
multiline:true
password:false
wordWrap:true
background:false
border:false
html:false
embedFonts:true
maxChars:null
maxhscroll:0
hscroll:0
variable:null
htmlText:hello world!
type:input
text:hello world!
autoSize:none
tabIndex:undefined
textColor:0
backgroundColor:16777215
borderColor:0
maxscroll:2
scroll:1
filters:undefined
sharpness:undefined
thickness:undefined
antiAliasType:undefined
gridFitType:undefined
[/code]
Shared Fonts in Flash IDE
Shared fonts, especially shared pixel fonts, are tricky business in the Flash IDE. Sometimes I wonder if it’s worth the effort, and whether I should just embed the fonts in each SWF. Alot of times I get blurred text when loading the pixel font from a shared library, but no blurring if the font is embedding in the swf itself. Shared fonts seem to work well with non-pixel fonts though; so if you dont need pixel fonts I would definitly use shared libraries. If you are looking at using shared fonts in your project I would recommend checking out Shared Fonts Manager.