Using embedded fonts with the Label control in Flash using ActionScript 3.0

by Peter deHaan on December 7, 2008

in Label

Working with embedded fonts in a Label component instance is very similar to working with a TextField instance. The main difference is that instead of using the embedFonts or defaultTextFormat properties of the TextField class, set the embedFonts or textFormat styles. In order to set the Label instance’s anti-alias type, set the antiAliasType property on the Label instance’s textField property, which contains a reference to the label’s internal text field.

For more information on embedding fonts, see the “Embedding Fonts” Quick Start on Adobe.com.

The following example demonstrates how to use embedded fonts and advanced anti-aliasing with a Label instance.

Full code after the jump.

// ActionScript 3.0
// Import the required component classes.
import fl.controls.Label;
 
// Create a new instance of the Font1 symbol from the document's library.  
var myFont:Font = new MyFont();
 
// Create a new TextFormat object, and set the font and size properties.
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.font = myFont.fontName;
myTextFormat.size = 8;
 
/* Create a new Label component instance, set the textField.antiAliasType property,
   set the embedFonts and textFormat styles, and add the label to the display list. */
var myLabel:Label = new Label();
myLabel.text = "The quick brown fox jumped over the lazy dog";
myLabel.autoSize = TextFieldAutoSize.LEFT;
myLabel.move(10, 10);
myLabel.textField.antiAliasType = AntiAliasType.ADVANCED;
myLabel.setStyle("embedFonts", true);
myLabel.setStyle("textFormat", myTextFormat);
addChild(myLabel);

Note: The previous example requires a font in your Flash document’s library with a linkage class of “MyFont”.

For more information on the Flash/ActionScript 3.0 Label component, see the “Using the Label component” Flash Quick Start on Adobe.com.

{ 2 comments… read them below or add one }

1 hans barzilay 04.14.09 at 8:02 am

Hello,

The Label class does not load.

I know about classpaths so this should not be the issue….

This code:
import fl.controls.Label;

Yields:
1172: Definition fl.controls:Label could not be found.

Many thanks in advance for your answer.
Hans, Pau France

2 Peter deHaan 04.15.09 at 7:53 am

hans barzilay,

Do you have an ActionScript 3.0 Label control in your Flash document’s library?

Peter

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: