Link to home
Start Free TrialLog in
Avatar of g8z
g8z

asked on

Embedding & Using Fonts in Flash MX or Flash 2004

Hello Flash Coders!

In order to dynamically create textfields in Macromedia Flash Actionscript one can use the createTextField() function, like this:

createTextField("some_txt", 1, 0,0,0,0);
some_txt.autoSize = "left";
some_txt.text = "Some Text";
my_fmt = new TextFormat();
my_fmt.bold = true;
my_fmt.font = "Jokerman";
some_txt.setTextFormat(my_fmt);

This code can be written inside the .FLA file or in a separate .AS (Actionscript) file. But if you happen to be using some exotic font in your program, there is always a chance that the client who downloads the .SWF might not have this font installed on their computer.

So, I need to know how to embed the font into the .FLA file, and still continue creating dynamic textfields using the above described method (using the embedded font, for example as shown above with the "Jokerman" font).

I need a small sample working .FLA file illustrating the solution.

thanks,
Darren
Avatar of elhy
elhy

Add the following line:

some_txt..embedFonts = true;
ASKER CERTIFIED SOLUTION
Avatar of negatyve
negatyve

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

To embed a font programmatically, you need to create a Font symbol in library. Give that symbol a linkage id and use it from actionscript.

I have made a sample file for you, you can download it from
http://www.abdulqabiz.com/files/font_embedding_sample.zip

However, i explain you concept, here are a few steps to achieve:

1) Create a font symbol, see details on it from http://livedocs.macromedia.com/flash/mx2004/main/06_typ16.htm#71545

2) Give a unique linkage id (click "linkage" from symbol property to assign linkage id)

3) Use it from actionscript, Consider our font symbols linkage id is "sDigital", I have prefixed with 's' to show its a font symbol.

Code on main timeline:

<code>

this.createTextField("message_txt", 0, 10, 100,20);

message_txt.embedFonts = true;

var tf = new TextFormat();
tf.font = "sDigital";

message_txt.setTextFormat(tf);

message_txt = "Hello world, this is embedded font...";

</code>

Hope it helps,

Regards,
Abdul