Flash Essential

Dynamically Embed Flash Font

Aug 14th 2008
6 Comments
respond
trackback

Often when using font in Flash it looks blurry and unprofessional. The reason for this is because the font has to be embedded so that it displays correctly. This just takes a few simple steps.

Lets say we have created a Dynamic text field inside our action panel and added it to the stage. Here's the code I have used.

var myFormat:TextFormat = new TextFormat();
myFormat.size = 15;
myFormat.color = 0×000000;
var myTextField:TextField = new TextField();
myTextField.autoSize = TextFieldAutoSize.LEFT;
myTextField.defaultTextFormat = myFormat;
myTextField.text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque lacinia elementum ante. Nam a dui. Donec pede urna, pharetra vel, convallis in, hendrerit at, nisl. Mauris semper condimentum massa. Quisque quis ipsum. Nulla congue mollis metus. In elit. Phasellus nisi leo, tristique laoreet, faucibus ut, pulvinar id, tellus. Integer vehicula. Duis vel mi. Nunc pellentesque justo et magna. Phasellus rhoncus imperdiet dui.";
myTextField.x = 100;
myTextField.wordWrap = true;
myTextField.multiline = true;
myTextField.y = 300;
myTextField.width = 500;
myTextField.height = 400;
addChild(myTextField);

Step 1 - Library Panel

Open up your library panel (window - library), Click the arrow on the top right and select New Font. You should now see the font symbols window.

Text Embedd Step 1

Step 2 Font Symbols Properties

Inside the font symbols property box choose a font style and give it a unique name. In this case I've used Font 1

Step 3 - Linkage

Right Click the font in your library and select Linkage. In the dialog box select Export for Actionscript and give your class a unique name. In this case I've used Font1.

Text Embedd Step 3

Step 4 - Actions

Now we just need to add these lines of code to complete the process. Open up your actions panel and copy and paste the code below.

var myFont:Font = new Font1();
myFormat.font = myFont.fontName;
myTextField.embedFonts = true;
myTextField.antiAliasType = AntiAliasType.ADVANCED;

Conclusion

Simple enough, now you have dynamically embedded your text via actionscript. No more blurry text in your applications!


This post is tagged , ,



Sponsors

Explore Recent





Monthly Archives



Friends and Affiliates



6 Comments

  1. Alexwebmaster

    Hello webmaster
    I would like to share with you a link to your site
    write me here preonrelt@mail.ru

  2. Great Sharing
    how about cs3 ?
    it same like cs4?
    thank…

  3. This was just what I was looking for. Thanks a boat load. Clean text from here on out, sweet.

Leave a Reply