RSS
email

Embedding Font in Flash CS3(using AS3)



Here is the way to embed fonts in AS3.0, and the code explanation follows

import flash.text.*;
var font:Font1=new Font1();
var txt_fmt:TextFormat=new TextFormat();
txt_fmt.font=font.fontName;
txt_fmt.size=24
var txt:TextField=new TextField();
txt.autoSize=TextFieldAutoSize.LEFT;
txt.defaultTextFormat=txt_fmt;
txt.embedFonts=true
txt.text="sara"
txt.selectable=false
addChild(txt);


Code Explanation:

Importing all the necessary classes..
import flash.text.*;

Creating new instance of the font from library..
var font:Font1=new Font1();
Here Font1 is the Linkage name given in the library



Creating TextFormat
var txt_fmt:TextFormat=new TextFormat();
txt_fmt.font=font.fontName;
txt_fmt.size=24

Note:
font is the instance name of Linkage name

Creating text field and applying the TextFormat created above
var txt:TextField=new TextField();
txt.autoSize=TextFieldAutoSize.LEFT;
txt.defaultTextFormat=txt_fmt;
txt.embedFonts=true
txt.text="sara"
txt.selectable=false

Adding the TextField to the DisplayList
addChild(txt);

Bookmark and Share

13 comments:

Anonymous said...

this helped me alot, thanks!

Anonymous said...

It was very useful. Thank you.

Anonymous said...

what if i want to use

txt.htmlText="sara"

???

Saravanan said...

HI,
you can use htnl tags there to decorate your text

mrc said...

thanks for posting this -- just found it on a search for embedding fonts and it was just what i needed!

-miranda

Anonymous said...

Thanks dude.

Niels said...

Indeed very useful. Thanks

Anonymous said...

it's not working

luke said...

thanks, it save my time!

Anonymous said...

Thanks! :)

chris said...

this is the wrong way man - you shouldn't embed the ENTIRE font family.

ÑØC†URÑÄL said...

Hi,
I did the same thing using Arial font and was able to embed the font for English language only. I was not able to see the Russian characters. I tried with "Arial Unicode MS" font also, but no luck...
Some one please help me?
I tested the font with this text "Джоан Брукс прибывает в Лондон".

Márcio Rosa said...

Great! Very simple and usefull. Thank you very much.

 

Recent Posts

Recent Visitors

Donate Me

About Me

My photo
Chennai, Tamil nadu, India
Nothing more to say about me.. Just a Action Script programmer / Flex developer having 4.5 years of experience.