Using an embedded font with the TextInput control in Flash using ActionScript 3.0

by Peter deHaan on December 22, 2008

in TextInput

The following example shows how you can use an embedded font with the Flash ActionScript 3.0 TextInput control by setting the embedFonts and textFormat styles.

Full code after the jump.

// ActionScript 3.0
/* Requires:
 * - TextInput component in Flash library
 * - Embedded font with class name "MyEmbeddedFont" in Flash library
 */
import fl.controls.TextInput;
 
var embeddedFont:Font = new MyEmbeddedFont();
 
var textFmt:TextFormat = new TextFormat();
textFmt.color = 0xFF0000;
textFmt.font = embeddedFont.fontName;
textFmt.size = 18;
 
var textInput:TextInput = new TextInput();
textInput.text = new Date().toString();
textInput.setStyle("embedFonts", true);
textInput.setStyle("textFormat", textFmt);
textInput.width = 300;
textInput.move(10, 10);
addChild(textInput);


Figure 1. Font Symbol Properties dialog box.

{ 3 comments… read them below or add one }

1 Ivo 05.19.09 at 8:12 am

Excellent, I was attempting to set embedFonts and textFormat through the TextInput.textField property for the longest time…

2 Oded 06.21.09 at 6:27 am

Hi. I’ve read this post as well as your article on http://www.adobe.com/devnet/flash/quickstart/embedding_fonts/ and I found that using the described instructions I can’t get the text fields to display unicode characters – only Latin1 characters can be embedded.

Do you know of a way to work around that limitation, as I really need to be able to embed fonts for unicode text.

Thanks.

3 Karl Benedikt 08.23.09 at 12:35 am

Unicode characters in Flash textInput? Does anyone know how include these?

Thanks.

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: