Archive for category ActionScript

How to deal with Lucida Grande Regular & Lucida Grande Bold font in ActionScript3

To embed Lucida Grande Regular &/or Lucida Grande Bold font in ActionScript3 you need to do next:

....
....
....
// declaring fonts
[Embed(source="fonts/Lucida_Grande_Regular.ttf", fontFamily="Lucida_Grande_Regular", fontWeight="normal", mimeType="application/x-font-truetype", embedAsCFF="false")]
private var LucidaGrandeRegular:Class;
[Embed(source="fonts/Lucida_Grande_Bold.ttf", fontFamily="Lucida_Grande_Bold", fontWeight="normal", mimeType="application/x-font-truetype", embedAsCFF="false")]
private var LucidaGrandeBold:Class;
....
....
....
....
// For Regular Font
// Create TextFormat with embeded font
var format:TextFormat = new TextFormat();
format.size = 17;
format.font = "Lucida_Grande_Regular";
format.bold = false;
format.italic = false;
format.color = 0xFFFFFF;
format.align = TabAlignment.CENTER;
// Use TextFormat
var text:TextField = new TextField();
text.embedFonts = true;
text.defaultTextFormat = format;

....
....
....

// For Bold Font
// Create TextFormat with embeded font
var format2:TextFormat = new TextFormat();
format2.size = 17;
format2.font = "Lucida_Grande_Bold";
format2.bold = false;
format2.italic = false;
format2.color = 0xFFFFFF;
format2.align = TabAlignment.CENTER;
// Use TextFormat
var text2:TextField = new TextField();
text2.embedFonts = true;
text2.defaultTextFormat = format2;

That’s it :) .
Please, write questions in comments.
Don’t forget share this post :)

Tags: , ,

How to use embed font in your ActionScript Flash application

To use embed font in your Flash application you need to do next:

1. Declare font and show TTF font location

[Embed(source="../../../../../../assets/fonts/MyFont.ttf", fontFamily="MyFont",fontWeight="normal", mimeType="application/x-font-truetype", embedAsCFF="false")]
    private var MyFont:Class;

take care about embedAsCFF=”false”. This is important part of code.

2. Create TextFormat object and use embed font it in.

var textFormat:TextFormat = new TextFormat();
textFormat.font = "MyFont"; // Here is font attached
textFormat.italic = false;
textFormat.color = 0x000000;
textFormat.size = 12;
textFormat.bold = false;

3. Create TextField object and start using TextFormat object BEFORE setting any text for TextField

var textField:TextField = new TextField();
textField.embedFonts = true;
textField.antiAliasType=AntiAliasType.ADVANCED;
textField.defaultTextFormat = textFormat;
textField.selectable = false;
textField.autoSize = TextFieldAutoSize.LEFT;
textField.text = "Here is text with embed font"

That’s all!

Please tell me if you know better solution, thanks.

Tags: , ,

Hire me!