Ah, the age old question, how does one embed fancy fonts into a Flash document? Particularly when you're creating dynamic text fields with code?
Well, it is actually easier than most people think. All you need to do is add a font to your library by clicking the options button in the Library panel and selecting New Font... well, ok, there's a few more steps than that. But after you do this, you can rotate and fade out dynamic text, so it's pretty useful.
There are probably more than a couple occasions when you want to embed a font, or modify its _alpha or _rotation properties without having to break apart the text and convert it into a MovieClip symbol. This quick mini-tutorial shows you how you can take your fancy fonts and embed them into your Flash document so the end users can see your font, even if they don't have it installed.
my_txt.embedFonts = true;
my_txt._rotation = 15;
my_txt._alpha = 10;
Enter some text into the dynamic text field and test the SWF file. You should see your text slightly rotated by 15° and nearly transparent.
This is useful if you need to create your text field with ActionScript. Using the same general techniques you can also create dynamically created text fields using the createTextField method, although this requires a few more steps...
With the font already embedded into your library, you can now use the following code:
var my_fmt:TextFormat = new TextFormat();
my_fmt.bold = true;
my_fmt.font = "Palatino 24pt Bold"; /* this is the LinkageID not the symbol name. */
my_fmt.size = 24;
this.createTextField("new_txt", this.getNextHighestDepth(), 10, 10, 100, 200);
new_txt.setNewTextFormat(my_fmt);
new_txt._rotation = 45;
new_txt._alpha = 50;
new_txt.autoSize = true;
new_txt.embedFonts = true;
new_txt.text = "hello world";
The only real snag in all of this is that if you are using a manually created text field, the font name is taken from the Symbol name in the library. But, if you are dynamically creating text fields, it seems that you have to use the Linkage identifier instead.
You can even build feedback forms with embedded forms by modifying the code to the following:
/* Note: You'll still the "my_fmt" code for this example to work. */
this.createTextField("new_txt", this.getNextHighestDepth(), 10, 10, 400, 300);
new_txt.setNewTextFormat(my_fmt);
new_txt._rotation = 10;
new_txt._alpha = 50;
new_txt.embedFonts = true;
new_txt.text = "";
new_txt.type = "input";
new_txt.multiline = true;
new_txt.wordWrap = true;
new_txt.border = true;
Note that the autoSize property was also removed since that just throws a giant wrench into the works.
Posted by jen on July 15, 2004 at 02:09 PMJust curious: any ideas on how to get rid of the 20k 1st frame load with this (or any other) font technique?
Posted by: Maarten van de Voorde at July 17, 2004 09:28 AMMaybe try this:
http://www.sharedfonts.com/
;-)
don't forget that if you do export your font symbol through the library, you woul dbe exporting the entire font...and most fonts sets have tons of characters you more than likely would never use. I usually embed fonts by creating a text field on the stage, then clicking on the "character..." button in the properties panel and then selecting the appropriate font outline (not "all").
Posted by: flashape at July 17, 2004 12:34 PMIs there anyway to justify text imported to a dynamice text box from a .txt file? even using action script?
Posted by: dopey at August 23, 2004 04:22 PMthis dosent work. or its working, but its still a great difference between non dynamical loaded text fields and dynamical text fields(who still looks awful). any clues?
is there any reason to use flash without action scripting?
re: justifying dynamic text fields.
I played around with the text fields for about 30 minutes and couldn't get dynamically loaded text to justify. I tried with all ActionScript and I tried with embedded fonts and I tried with just a text field on the Stage w/ LoadVars. None of them seemingly justify dynamic content.
Maybe it works and I'm just not seeing the solution, but it looks like you can only left, center or right align stuff.
Posted by: peter at August 25, 2004 11:00 AMHello!
I'm new in flash, and i'm interested in insert my fonts in flash to anybody see. I reed your comment about de embedding fonts, and i try do to the same in flash with sucess, but i did't understand how to export a font symbol.
I tryed do to the export in linkage to a root folder but didn't export anything. I tryed too insert the font i've chosen in the same root folder but the file SWF don't get the font.
I'm Lost! :)
I think must be very simple but a don't know.
Please give some direction!
sorry my english :)
Posted by: Nuno Lopes at August 27, 2004 08:30 AMHello,
How do you use a embed font on a dynamic component, such as the TextArea Component?
Posted by: Robert S at October 19, 2004 08:36 PM