AIR Mobile Embedded Font - actionscript-3

I am trying to change the default font of a text field in an AIR Mobile app.
What I dos first embed the font using this line:
[Embed(source='C:/WINDOWS/Fonts/ARIAL.TTF', fontName="_Arial", mimeType="application/x-font-truetype")]
After that, I create a TextFormat with this font: style.font = "_Arial"; and set it to the text field: tf.setTextFormat(style);
Sadly, the font does not change.
Anyone knows what I am doing wrong?

You need to use:
tf.defaultTextFormat = style;
There are differenced between defaultTextFormat and setTextFormat
setTextFormat
defaultTextFormat
UPDATE:
not sure why this is not working what you have there, but i managed to make it working, just replace the font embedding line with this:
[Embed(systemFont="Arial", fontName="_Arial", mimeType="application/x-font-truetype", embedAsCFF="false")]

Did you set the textfield.embedfont = true. ?

Related

Japanese text in TextField with embedded font

In my ActionScript 3 project I use TextField with embedded font set to true and isHTML set to true. Everything works fine when I display latin characters.
But when I want to display Japanese characters they do not appear. Actually it is expected to be like this because Japanese font is not embedded.
Is there is a way to fall back to system font if embedded font doesn't have glyphs for certain characters?
Try to use hasGlyphs("..."); on a Font instance. I had some problems with it but in general it works alright, hopefully it works for Japanese too. Then you can simply use _sans if there is no japanese glyphs.
Edit:
I have no way to test this now but I assume something like this would work:
import flash.text.Font;
var myFont:Font = new MyFont(); // Embedded font in library, linkage set to 'MyFont'
if(myFont.hasGlyphs("Hello!")) {
field.embedFonts = true; // Not sure whether this is necessary in case of HTML text
field.htmlText = "<p><font color='#ff0000' face='" + myFont.fontName + "'>Hello!</font></p>";
}
else {
field.embedFonts = false;
field.htmlText = "<p><font color='#ff0000' face='_sans'>Hello!</font></p>";
}

as3 .text not working

So heres the code Im using:
endScreen.scorePrint.text = String(score);
endScreen.distancePrint.text = String(distance);
And it doesent show anything, while the very same code in other places in my app works, I tried to embed fonts and stuff but I still get blank space. what am I doing wrong?
EDIT:
endScreen is a MovieClip without AS linkage, its manipulated by .visible , scorePrint and distancePrint are a part of that MovieClip.
scorePrint and distancePrint are identical in all but names and are as following:
classic text -> dynamic text
Try
endScreen.scorePrint.text = "" + score;
if not, then does
trace("" + score);
show anything?
I fixed it, the problem was anti-aliasing. I changed from anti-aliasing for readability to device fonts. that fixed both fields.
Thanks for support :)

Basic TextFormat change is doing nothing

Code:
var BoldTextFormat:TextFormat = new TextFormat();
BoldTextFormat.bold = true;
weapons[player.activeWeapon].weaponName.defaultTextFormat = BoldTextFormat;
This seems very simple, but it is not doing anything! The text is not becoming bold at all.
Using weapons[player.activeWeapon].weaponName.setTextFormat(BoldTextFormat); does nothing also.
These traces:
trace(weapons[player.activeWeapon].weaponName);
trace(weapons[player.activeWeapon].weaponName.defaultTextFormat);
trace(BoldTextFormat);
Result in this output:
[object TextField]
[object TextFormat]
[object TextFormat]
And this is the text field I am trying to make bold:
I have embedded the bold font:
What could possibly be wrong? There are no errors. Tracing the text field's text shows the correct text, so that can't be the problem.
You might need to embed the bold font, your image shows 'Regular' font.
Ok, I figured out the magic here. Likely why it started working for you is that you actually set the bold font for your field.
But here's the magic. In the library, right-click on the bold font and choose properties. Then go to the actionscript settings and enable :
export for actionscript
Next, in your code you need to add this line :
BoldTextFormat.font = "Times New Roman Bold";
That should work.
Sadly, the .bold of the TextFormat doesn't seem to automatically find the bold version.
Try :
weapons[player.activeWeapon].weaponName.setTextFormat(BoldTextFormat);
defaultTextFormat applies to text that is added after you set the format, if you want to change the format of text that is already set you should use setTextFormat

Content by using AntiAliasType.ADVANCED;

We are using following code for displaying html text in a dynamic classic text field.
var txtFld = new TextField();
txtFld.x = 10;
txtFld.y = 0;
txtFld.wordWrap = txtFld.multiline = true;
txtFld.width = 1190;
txtFld.autoSize= "left";
txtFld.embedFonts = true;
txtFld.antiAliasType=AntiAliasType.ADVANCED;
txtFld.htmlText = (Dynamic text);
If using "Normal" AntiAliasType instead of Advanced then everything is working fine. But text quality of application is not good, so i have used "AntiAliasType.ADVANCED" to make the text quality better.
We are getting lots of problem by using "AntiAliasType.ADVANCED" like visibility of text with long text, not able to embed the "GGSubscript" font etc.
Also if I user flash player version 10.3 or above then the text is also visible but the fonts are not embedded in it.
I have tried number of flash player version. Please suggest if this can be correctly some how.
Thanks,
Ashmesh Thakur

Can't embed multiple fonts and use them in same textfield - cs5, as3

having a bit of trouble getting embedded fonts to work. The inconsistency with this is driving me crazy. I've gotten this to work before but not since going to cs5.
My set up is as follows:
I have a dynamic textfield on stage named "tf".
The following code populates the textfield and attempts to style one word, "love" in the sentence with a different font.
_style = new StyleSheet();
var styleObj = new Object();
styleObj.color = '#FF0000';
styleObj.fontFamily = 'Futura Bold Oblique';
_style.setStyle('.otherText', styleObj);
tf.styleSheet = _style;
tf.htmlText = 'I <span class="otherText">love</span> it when stuff works!';
The font is embedded and set to export for actionscript with the export name Font1. The word "love", which is supposed to be displayed as the font Futura Bold Oblique just disappears. It makes no difference if I use the font screen name listed in the properties panel for that font or if I use the export instance name I gave it.
My sentence looks like : I it when stuff works! As you can see, "love" is gone. Come on people, show me some love! lol.
Anyone have an idea why this isn't working. This is highly essential to my daily work and its driving my crazy!! Thx!
I have been playing around with this since posting, hoping that maybe that specific font was causing the trouble, but its not the font. I tried using different styles of Helvetica Neue as separately embedded fonts and got the same result.
Fixed it, sort of. using enumerateFonts. This lists the fonts' names as Flash sees them. Copy and paste from the output window, and use that for the stylesheet fontFamily property. It still seems that Flash thinks some different styles from the same family, like Futura Bold and Futura Bold Oblique are the same; in my case it listed them both as Futura Book. In order to get the Oblique text in there I had to embed two separate versions of the font, Futura and Futura BT.
private function getFontNames():void
{
var fontArray:Array = Font.enumerateFonts(false);
fontArray.sortOn("fontName", Array.CASEINSENSITIVE);
for(var i:int = 0; i<fontArray.length; i++)
{
trace(fontArray[i].fontName);
}
}