Skip to main content
February 3, 2014
Question

How to embed a font air Android App????

  • February 3, 2014
  • 2 replies
  • 2450 views

Hi, im new to this forum so please forgive me if i question in the wrong section.

I am Beginner and am working on an air android game in flash cs6.. i need embed fonts please help me sort out htis problem..

This topic has been closed for replies.

2 replies

Inspiring
February 9, 2014

The easiest for me is to simply embed your font into your main document class, like this:

package

{

     import flash.display.Sprite;

     import flash.text.*;

     public final class MyApp extends Sprite

     {

          [Embed(source="../fonts/ITCAvantGardeStd-Bold.otf", embedAsCFF = "false", fontWeight="bold", fontName = "ITCAvantGardeStd_DemiAndBold", mimeType = "application/x-font-truetype", unicodeRange="U+0021-U+007E, U+00A9, U+00AE")] // Main characters + Copyright and Registered glyphs

          static public var ITCAvantGardeStdBold:Class; // that's what the embed gets baked into

          Font.registerFont( ITCAvantGardeStdBold ); // do this once per font

          public function MyApp():void // Constructor

          {

               // Create a textformat that uses the font

               var tft:TextFormat = new TextFormat( "ITCAvantGardeStd_DemiAndBold", 20, 0xffff00, true );  // size = 20 pix, color is yellow, bold = true, matching the font weight

               // create a text field

               var tf:TextField = new TextField();

               with ( tf )

               {

                    antiAliasType = AntiAliasType.ADVANCED; // optional

                    defaultTextFormat = tft;

                    embedFonts = true; // this is using an embedded font

                    width = 100;

                    autoSize = TextFieldAutoSize.LEFT;

                    wordWrap = true;

                    text = "Hello world ! blah blah blah blah blah blah blah blah blah blah blah blah";

                    height = textHeight + 8; // nice and tight

                    border = true; // for fun

                    borderColor = 0xffff00; // yellow

               }

               addChild( tf );

          }

     } // end of: class

} // end of: package

The embed statement contains several optional properties, like fontWeight, fontStyle, and fontFamily.

Check here for info:  http://divillysausages.com/blog/as3_font_embedding_masterclass

Note: Alternatively, you could use Flash Professional to embed the font into the document class via the IDE ( like so: http://www.adobe.com/devnet/flash/quickstart/embedding_fonts.html ).

Also, for these kinds of questions, I recommend:

1) O'Reilly -- Essential ActionScript 3.0

2) O'Reilly -- ActionScript 3.0 Cookbook

Known Participant
February 3, 2014

Create a css file for your project. Embed font as both types.

@font-face {

   src: url("assets/fonts/Arial-Regular.ttf");

  fontFamily: "arialCFF";

  embedAsCFF: true;

}

@font-face {

  src: url("assets/fonts/Arial-Regular.ttf");

  fontFamily: "arial";

embedAsCFF: false;

}

.anCFF11 {

fontSize: 11;

fontFamily: arialCFF;

}

Then for a label just change the stylename to 'anCFF11'

For StyleableTextField set via the html text -

var fullnameSS:StyleSheet = new StyleSheet();

fullnameSS.parseCSS( '.fullname{color: #333333; fontSize: 15; font-Family: "arial"; fontWeight: bold}');

_status.styleSheet = fullnameSS;

_status.htmlText = "<span class='fullname'><b>My Text</b>";