When developing with Adobe Flash, you often come across the need to use some fonts that are not part of the standard set loaded with the OS, therefore the developer is never sure if the font used will be displayed or not.
More so if using pixel-fonts.
A solution to this dilemma is to incorporate the fonts within the SWF itself.
Let's see how'
As usual I create an FLA and save it as ' fonts.fla ' .
I create the Document Class, an AS file saved as ' Fonts.as ' .
What I write in the Fonts class:
Code:
package
{
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
public class Fonts extends MovieClip
{
private const testo:String='Lorem ipsum dolor sit amet,consectetuer adipiscing elit.\n'+
'Aliquam ac felis. Pellentesque varius adipiscing ligula.'+
'Duis porttitor, libero ut fringilla pellentesque,\n'+
'nunc nisl hendrerit tellus, nec dignissim mauris pede at risus\n'+
'nunc nisl hendrerit tellus, nec dignissim mauris pede at risus.';
private var field:TextField;
public function Fonts()
{
createField();
}
private function createField():void
{
field=new TextField();
field.autoSize=TextFieldAutoSize.LEFT;
field.defaultTextFormat=getFormat();
field.text=testo;
addChild(field);
}
private function getFormat():TextFormat
{
var format:TextFormat=new TextFormat();
format.font='FFF Aquarius';
format.color=0x333333;
format.size=8;
return format;
}
}
}
And here is the result:
This class has only created a text field and assigned a format and some text to it.
Now we go back to our FLA and create an empty dynamic text field.
With the empty text highlighted, I assign the preferred font and then click on 'embed' as in the pic below:
In the open window, you can select the char sets you want to use.
This way we have the certainty that at the moment of publishing, our SWF will avail all the characters we've used to display during the application execution. The text field is only used as an intermediary, therefore I'd suggest you kept it unavailable, hence invisible and just outside the stage.
If instead I wanted to create my text fields to be able to write text on them, you can just perform an operation very similar to the previous one and, maintaining the text field highlighted (still dynamically) and opening the char sets window, click on the ' auto fill' button and Flash will expert to the SWF only the characters contained in the text field.
Stay tuned !