Skip to main content
Known Participant
June 30, 2011
Answered

Embedded font does not show up on Android

  • June 30, 2011
  • 1 reply
  • 4930 views

I am using CS5.5 and have added the following to my class:

[Embed(source = "C:\\Windows\\fonts\\Kinds_Plain.ttf", fontFamily = "KidsPlain", embedAsCFF = "false")]

It works when running on the desktop.  The text typed is in this font.  But when I packaged and installed the app on my Android device, the text typed is changed to the default font.

Any help is appreciated!

Thanks in advance,

aimaob

This topic has been closed for replies.
Correct answer Joe ... Ward

Oops!  I forgot to embed it in CS5.5.

I also created a class "Kids" (Text -> Font Embedding -> ActionScript),  and removed the Embed statement from the code.

I write the following code to set up the messageArea:

private var kidsPlainFont:Font = new Kids();

private var textFormat:TextFormat;

private var messageArea:TextField;

textFormat = new TextFormat();

textFormat.font = kidsPlainFont.fontName;

messageArea.defaultTextFormat = textFormat;

addChild(messageArea);

Again, it works on the desktop but does not work on the Android device.  What am I missing?


When you input text in a text field, the runtime positions a native text input control over the Flash TextField object. Since native controls can't use embedded fonts, the closest system font is used. On Android (but not iOS) you can use TLF to create a text input control that is entirely drawn in Flash and thus can use embedded fonts during input. (I'm not sure if the Flex components support this on mobile, though, so you might still have to make your own if using Flex.)

1 reply

relaxatraja
Inspiring
July 1, 2011

C:\\Windows\\fonts\\Kinds_Plain.ttf  Is this the same path you used to show on android?

use just like:

[Embed(source = "Kinds_Plain.ttf", fontFamily = "KidsPlain", embedAsCFF = "false")]

and attach the file with the swf while packaging.

aimaobAuthor
Known Participant
July 1, 2011

Thanks for you reply!

I have tried it and packaged the font together with the rest of the files.  It still does not work.

The library class file with the Embed statement is under a directory com/directory/directory and I have put the font file in the same directory of this class file.  The main class file resides in another directory.  In my main class file, I use the import statement to import the library class file.

Compilation is fine and the font shows up when running on the desktop.  Somehow, it still does not work on Android.  Is there something I am missing?  Should all files reside in the same directory in order for it to work?

aimaobAuthor
Known Participant
July 8, 2011

Yes, this looks like this is the problem.  I created a TLFTextField and ran into another problem and have posted my message on Action Script 3 Discussions which I think this problem is more relevant to AS3 in general.


I have written the following test program to use TLFTextField:

---------------------------------------------------------------------------------------------

import fl.text.TLFTextField;

import flashx.textLayout.formats.TextLayoutFormat;

import flashx.textLayout.elements.TextFlow;

[Embed(source = "Kids_Plain.ttf", fontFamily = "Kids", embedAsCFF = "false")]

var kids:Class;

var myFormat:TextLayoutFormat = new TextLayoutFormat();

myFormat.fontFamily = "Kids";

myFormat.fontSize = 24;

var tlfTextField:TLFTextField = new TLFTextField();

tlfTextField.x = 50;

tlfTextField.y = 50;

tlfTextField.width = 200;

addChild(tlfTextField);

var myTextFlow:TextFlow = tlfTextField.textFlow;

myTextFlow.hostFormat = myFormat;

myTextFlow.flowComposer.updateAllControllers();

tlfTextField.appendText("Testing this");

----------------------------------------------------------------------------------------------------

I am using CS5.5, have added the Flex library path, and chosen "Merge into code".

It runs perfectly on the desktop, but not on the Android.  I have already included the Kids_Plain.ttf file in the apk.  The text shows but the font is the system default font.

Any help is appreciated!