Home » ActionScript 3.0, Android, Flash CS4, Flash CS5

Actionscript as3 Dynamic Embedding fonts in Flash CS5, runtime font embed

25 February 2011 3 Comments
Share on Facebook

On tutorial Request of “Dynamic Font embedding in as3″ I am writing this tutorial of how to embed fonts in Flash CS5 using actionscript 3.0 ( as3 ).

Difficulty:
Beginner to Intermediate

In this article we are going to study how to runtime font embed in actionscript 3. In this article we are going to see

  • Add Font in library and linkage
  • How to create textfield in runtime
  • How to embed fonts in runtime using as3

Add Font in library and linkage:

Step 1: Open New document in Adobe Flash CS5

Step 2: Open Library from Window Menu -> Library or CTRL + L , Now Library panel opened.

Step 3: Click on top right corner as in the picture below and New Font…

Step 4: Select the font from the “Options” Tab

Step 5: Next Select the “ActionScript” tab in right of options tab and check the “Export for ActionScript”. Note the class name and enter OK.

Note: Leave the default selections as it is. Remember the Class Name.

How to create textfield in runtime:

Step 6: Select frame 1 on timeline and press “F9″. paste the below code

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

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

//Creating the text Field
var txt:TextField=new TextField();
txt.autoSize=TextFieldAutoSize.LEFT;
txt.defaultTextFormat=txt_fmt;
txt.embedFonts=true
txt.text="Designscripting.com"
txt.selectable=false;

//Adding the textfield to the flash player display list.
addChild(txt);

Note: In the above code we create the textfield in runtime and assigning some text to it.

How to embed fonts in runtime using as3:

var font:Font1=new Font1();

Note: Here the Font1 is the class Name, We have given at the time of “Export for ActionScript” at Step5

Entire code for Embedding fonts in Flash CS5 and actionscript 3.0

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="Designscripting.com"
txt.selectable=false
addChild(txt);

Conclusion:

From this article we have learn how to embed / dynamic linking of fonts in actionscript 3.0 using Flash cs5.
Comment for any clarification and request a tutorial through contact page.

GET THE UPDATES VIA EMAIL

We don't share your email anywhere, grab our rss via feedburner


3 Comments »

  • Arin said:

    well! this is amazing! i found my answer while i was asking here…
    if you want to embed persian or arabic fonts you should use TLFTextField instead of TextField class.( Both when embedding and in the actionscript ). To do this when embedding set the outline format to TLF and in actionscript use “var txt:TLFTextField = new TLFTextField()”

  • Hugh said:

    I tried running the code from step 6 and kept getting the following error:

    1120: Access of undefined property font.

  • admin said:

    Check with the Flash version u r using

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.