Thursday, April 22, 2010

use an embedded font

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.

No comments:

Post a Comment