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.

Tagged with:
 

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

  1. Ivo says:

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

  2. Oded says:

    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. Unicode characters in Flash textInput? Does anyone know how include these?

    Thanks.

  4. Ernesto Pino says:

    Gracias por compartir esta información. Ha sido muy valiosa para mi.
    He solucionado un gran problema en una aplicación de Facebook desarrollada con AS3 y Flash CS5.

  5. mintakastar says:

    hello =D

    well even this post is some years old , it really helped me =D thanks !, this was freaking me out !!

    this solution solves the problem of spanish/latin characters like ñ or Ñ

    I saw a solution like

    textField.embedFonts = true ;
    textField.textFormat= someTextFormat;

    but there was not for TextInput or TextArea (only text field)

    textField.setStyle("embedFonts", true);
    textInput.setStyle("textFormat", textFmt);

    so this helped me so much xD

Leave a Reply

Your email address will not be published.

You may 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="" highlight="">

Spam Protection by WP-SpamFree