Copy link to clipboard
Copied
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
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.)
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Are you publishing with flash cs5.5 then embed your font within your flash file.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.)
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Finally got it working with FontDescription. The code is as follows:
import flash.text.engine.FontDescription;
import flash.text.engine.ElementFormat;
import flash.text.engine.TextBlock;
import flash.text.engine.TextElement;
import flash.text.engine.TextLine;
[Embed(source = "Kids_Plain.ttf", fontFamily = "Kids", embedAsCFF="true")]
var Kids:Class;
var fd:FontDescription = new FontDescription();
fd.fontLookup = flash.text.engine.FontLookup.EMBEDDED_CFF;
fd.fontName = "Kids";
var elementFormat:ElementFormat = new ElementFormat(fd);
var string:String = "This is a test";
var textBlock:TextBlock = new TextBlock();
var textElement:TextElement = new TextElement(string, elementFormat);
textBlock.content = textElement;
var line:TextLine = textBlock.createTextLine(null, 100);
line.x = 50;
line.y = 50;
addChild(line);
Copy link to clipboard
Copied
Great!
Copy link to clipboard
Copied
It works on AIR2.6 running Android, but not AIR2.5. Better open a new post since this question is tagged as answerd.