Embedded Fonts in AS3 and IE: Is the syntax correct? - actionscript-3

I spent a good bit of time this morning trying multiple solutions I found throughout the site but unfortunately, none of them truly worked. Here's the problem. I believe that my process of font embedding is working because I purposely removed the fonts from my machine and I see them showing up in the flash player. However, they do not show up on our Windows test machine (in either IE or FF) and I can't seem to figure out why. As I mentioned, I tried several of the solutions found throughout the site but it didn't seem to make a difference. Here is excepts of the class and constructor that I have built:
public class MyClass {
[Embed(source = "../../fonts/DroidSans.ttf",
fontName = "DroidSans",
mimeType = "application/x-font-truetype",
fontWeight = "normal",
fontStyle = "normal",
unicodeRange = "U+0041-U+005A, U+0061-U+007A, U+0030-U+0039, U+002E-U+002E",
embedAsCFF = "false")]
private var droidSansFont:Class;
[Embed(source = "../../fonts/DroidSans-Bold.ttf",
fontName = "DroidSansBold",
mimeType = "application/x-font-truetype",
fontWeight = "normal",
fontStyle = "normal",
unicodeRange = "U+0041-U+005A, U+0061-U+007A, U+0030-U+0039, U+002E-U+002E",
embedAsCFF = "false")]
private var droidSansBoldFont:Class;
.
.
.
public function MyClass() {
_flVersion = String(flash.system.Capabilities.version);
_baseFont = (_flVersion.indexOf("10,") != -1) ? "Arial" : "DroidSans";
_boldFont = (_flVersion.indexOf("10,") != -1) ? "Arial" : "DroidSansBold";
buttonFormat = new TextFormat();
buttonFormat.font = _baseFont;
buttonFormat.size = 10;
buttonFormat.color = 0x000000;
buttonFormat.bold = false;
buttonFormat.align = "center";
.
.
.
}
}
If anyone can offer up a solution or point me in the right direction, it would be most helpful.

Are you setting embedFonts=true on your TextField?
And be careful with version test:
_flVersion.indexOf("10,")!=-1
This could match anywhere in the version String. You negaitve logic is confusing me a little, but thinking carefully, you check will DISABLE embeded fonts in Flash Player versions, for example: 10,1,100 and 12,10,115
Assuming you do intend to disable embedded fonts in FP10, you could possibly change your condition to the following (which won't match 12,10,115):
_flVersion.indexOf("10,")==0
I'd then put this in a commented getter function to make your code more readable:
// No embedded fonts for flash player 10
private static var _flVersion:String = String(flash.system.Capabilities.version);
private function get use_embedded_fonts():Boolean {
return _flVersion.indexOf("10,")!=0;
}
Also, you'll only want to set the embed flag when using the embedded Droid font and not Arial:
_baseFont = (!use_embedded_fonts) ? "Arial" : "DroidSans";
_boldFont = (!use_embedded_fonts) ? "Arial" : "DroidSansBold";
_embed_flag = use_embedded_fonts;
textfield.embedFonts = _embed_flag;
...

Related

AS3 TextField Fonts

I have problems setting a font in AS3. I have tried several different things using ressources from forums and questions but I can't get it to work.
Here's the code I use:
private function addContentToMovieClips(Text:String, MC:MovieClip):void
{
var myFont = new Trebuchet();
var tFormat:TextFormat = new TextFormat();
tFormat.font = myFont.fontName;
tFormat.color = 0x000000;
trace(tFormat.font);
var tf:TextField = new TextField();
tf.defaultTextFormat = tFormat;
tf.embedFonts = true;
//tf.antiAliasType = AntiAliasType.ADVANCED;
tf.text = Text;
MC.addChild(tf);
tf.width = 300;
}
In the library, I have a Font named "font2" with AS linkage "Trebuchet". I get no compiler errors and text seems to be created on the screen but nothing is displayed.
The following line is for debugging:
trace(tFormat.font);
And returns "Trebuchet MS" as expected.
I'd be very grateful if you can help me understand why this does not work!
Cheers,
Patrick
Edit: when removing
tf.embedFonts = true;
the text is displayed with the correct font. Not sure why but this does the trick for now.
You should have pasted the code where you embed the font. But since I've had the same problem, I guess you missed the embedAsCFF directive:
[Embed(source="../someFont.ttf",
fontName = "myFont",
mimeType = "application/x-font",
fontWeight="normal",
fontStyle="normal",
unicodeRange="englishRange",
advancedAntiAliasing="true",
embedAsCFF="false")]

Why can't I display embedded fonts in AS3?

I have gone through all topics on Embedding fonts in AS3 I could find,a nd tried all solutions. I'm probably missing something obvious, but I don't fully understand what I'm doing so please guide me in the right direction. Many of the answers involve Flash Builder or another tool but I use FlashDevelop. No idea whether that matters.
I have this line in my Main.as:
[Embed(source = "assets/SKA_75_marul_CE_extended.ttf",
fontName = "SKA_75_marul_CE_extended",
fontWeight = "bold",
advancedAntiAliasing = "true",
mimeType = "application/x-font")]
public static var SKA_75_marul_CE_extended:String;
And this exists in the constructor of an extended Sprite called Pointer.as:
var format:TextFormat = new TextFormat();
format.font = "SKA_75_marul_CE_extended";
format.color = 0xFFCCCC;
format.size = 20;
var label:TextField = new TextField();
label.defaultTextFormat = format;
label.text = "test";
label.embedFonts = true;
label.antiAliasType = AntiAliasType.ADVANCED;
//label.setTextFormat(format); --> I tried this too, didn't work...
label.defaultTextFormat = format;
label.x += img.width + 50;
this.addChild(label);
The only way I've found to get it to display anything is if I turn off embedFonts. I've tried embedding C:/windows/fonts/arial.ttf without success.
It seems that embedding fonts is a dark art like no other and I must concede after 1 hour of struggling. Please send help.
UPDATE:
Here's the working code, turns out it was due to having the correct order of operations...:
[Embed(source="assets/SKA_75_marul_CE_extended.ttf",
fontName = "myFont",
mimeType = "application/x-font",
fontWeight="normal",
fontStyle="normal",
unicodeRange="U+0020-U+007E",
advancedAntiAliasing="true",
embedAsCFF="false")]
private var myEmbeddedFont:Class;
var tf:TextFormat = new TextFormat( "myFont", 20,0xffffff );
var t:TextField = new TextField;
t.embedFonts = true; // very important to set
t.defaultTextFormat = tf;
t.text = text;
t.x += img.width + 50;
t.width = 700;
this.addChild( t );
It's most DEFINITIVELY a "dark art" to get embedded fonts to work right. I would first check if "SKA_75_marul_CE_extended" is the actual name the font has in its metadata (I used Suitcase Fusion to extract the name). I've also seen TTF fonts that Flash simply refuses to embed (perhaps invalid metadata causes the embed system to fault). I would continue testing with a known working font until you find the actual problem in case it is a font file problem.
One thing I noticed is "public static var SKA_75_marul_CE_extended:String;"... shouldn't this be of type Class?
FlashDevelop font embed reference from someone who had issues:
http://www.flashdevelop.org/community/viewtopic.php?p=28301

fonts not working any more (flex)

my fonts got screwed up when moving my flash-project to flex. They don't show up any more (strange thing is I don't get any error messages).
Please - can somone help me out with this problem? Thank you.
[Embed(source="../../../../../assets/fonts/Orbitron/TTF/orbitron-medium.ttf", fontFamily="Orbitron", fontWeight="medium", mimeType='application/x-font', embedAsCFF='false')]
public static const OrbitronMedium:Class;
private var font:String;
font = new Library.OrbitronMedium();
private var statsTxtFormat:TextFormat;
statsTxtFormat = new TextFormat();
statsTxtFormat.font = font;
statsTxtFormat.bold = false;
statsTxtFormat.size = 14;
statsTxtFormat.color = 0xfdfea1;
statsTxtFormat.align = TextFormatAlign.RIGHT;
statsTxtFormat.kerning = true;
statsTxtFormat.letterSpacing = 1;
It looks as if "../../../../../" could be the problem.
Try moving the font closer to the file, it will reduce the chances of a bad embed.

AS3 Text Input accents

I create an AS3 TextField set to Input mode dynamically through code, but when the user tries to input some special characters (eg. á à é è í ì ó ò ú ù ç) they simply do not appear on the TextInput.
Copying and pasting them to the textfield works, but I'd prefer if the user could directly type them.
Here's a quick test demonstrating this:
package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
public class TextInput extends Sprite
{
public function TextInput()
{
super();
var t:TextField = new TextField;
t.type = TextFieldType.INPUT;
addChild(t);
}
}
}
This creates a textfield where the user can type, but I can't type special characters like à.
Many thanks.
If you can paste it into the Input field, you should be able to type it.
If you start a new Flash document, using the same font as you are above create an Input textfield on the stage with the following settings:
Embed the normal glyphs
Embed the extended latin glyphs
And this should work, as:
Now if all this works, it might have something to do with the way the class is written.
Writing classes that embeds fonts is frankly a pain. Make sure you embed the font in the library and export it for action script:
Following that, you need to use the following code:
// The name of the font class
var _font:Calibri = new Calibri();
var _textFormat:TextFormat = new TextFormat();
_textFormat.font = _font.fontName;
_textFormat.size = 16;
// For some weird reason the ordering here is important. I remember mucking around with this for ages for an old project. EmbedFonts must come last
var _textField:TextField = new TextField();
_textField.defaultTextFormat = _textFormat;
_textField.type = TextFieldType.INPUT;
_textField.embedFonts = true;
addChild(_textField);
And that should have it all working:
** EDIT **
To those using FlashDevelop, etc you can use the following method:
public class Main extends MovieClip {
[Embed(source='assets/HOBOSTD.OTF', fontName='_hobo', embedAsCFF="false")] public static const HOBO:Class;
public function Main() {
var _font:Font = new HOBO() as Font;
var _textFormat:TextFormat = new TextFormat();
_textFormat.font = _font.fontName;
_textFormat.size = 22;
var _textField:TextField = new TextField();
_textField.embedFonts = true;
_textField.defaultTextFormat = _textFormat;
_textField.autoSize = TextFieldAutoSize.LEFT;
_textField.antiAliasType = AntiAliasType.ADVANCED;
_textField.type = TextFieldType.INPUT;
addChild(_textField);
}
}
And you will get the following:
Now note, the font file must be either relative to your project, or the source can point to the C:\windows\font folder if you choose. In the above example, I copied the font to my assets folder.

Papervision rendering PNGs with transparency thats inside a movieclip

I'm an actionscript dude - I'm working on a papervision game.
I have an asset of which is 127 pngs in a sequence for an animation.
I can happily project this onto my papervision plane. Problem is, there is no transparency. I Can't use a BitmapFileMaterial as I have many pngs -
can anyone suggest how to do this.
Very very grateful -
myMaterial.transparent = true
Or something like that, check out the docs if that doesn't work.
this is my code so far. A simplified version edit - Papervision 2.0.0
package com.strangemother.gameObjects
{
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Plane;
public class Biorod extends DisplayObject3D
{
/*
My flash movieclip with 127 pngs in sequence
*/
private var textureMC:BiorodTexture = new BiorodTexture();
private var movieMat:MovieMaterial = new MovieMaterial(textureMC, true, true)
var plane:Plane = new Plane(movieMat, 300,300,1,1);
public function Biorod()
{
textureMC.id = 'biorod';
movieMat.animated = true;
movieMat.doubleSided = true;
// movieMat.interactive = true;
movieMat.smooth = true;
movieMat.movieTransparent = true;
this.addChild(plane);
}
}
}
Reading over google - There seems to be a bug -
private var movieMat:MovieMaterial = new MovieMaterial(textureMC, true, true)
set to
private var movieMat:MovieMaterial = new MovieMaterial(textureMC, false, true)
and later setting
movieMat.movieTransparent = true;
seems to work.
Uber thanks for your help -pointed me in the right direction.