fonts not working any more (flex) - actionscript-3

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.

Related

actionscript 3 as3 flash AIR font embed external

[Embed(source='/assets/calibri.ttf', fontName="Font", mimeType="application/x-font-truetype" embedAsCFF="false")]
private static var calibri:String;
I Looking from tutorial and get code like above and look like it's must on Class?
can I use it without class? or maybe an example for font loaded class please?
Use the embed param fontFamily. This string you can use to set the font.
[Embed(source='/assets/calibri.ttf', fontFamily="calibri", mimeType="application/x-font-truetype" embedAsCFF="false")]
var CalibriFont:Class;
var tf:TextField = new TextField();
tf.embedFonts = true;
addChild(tf);
var tff:TextFormat = new TextFormat();
tff.font = "calibri";
tf.defaultTextFormat = tff;
tf.htmlText = "HELLO";

Loading images using the URLRequest

recently started to learn ActionScript 3 and already have questions.
question remains the same: I'm uploading a picture using the object Loader.load (URLRequest). Loaded and displayed a picture normally. But it is impossible to read the values of attributes of the image height and width, instead issued zero. That is, do this:
var loader:Loader=new Loader();
var urlR:URLRequest=new URLRequest("Image.jpg");
public function main()
{
loader.load(urlR);
var h:Number = loader.height;// here instead of the width of the image of h is set to 0
// And if you do like this:
DrawText(loader.height.toString(10), 50, 50); // Function which draws the text as defined below
// 256 is displayed, as necessary
}
private function DrawText(text:String, x:int, y:int):void
{
var txt:TextField = new TextField();
txt.autoSize = TextFieldAutoSize.LEFT;
txt.background = true;
txt.border = true;
txt.backgroundColor = 0xff000000;
var tFor:TextFormat = new TextFormat();
tFor.font = "Charlemagne Std";
tFor.color = 0xff00ff00;
tFor.size = 20;
txt.x = x;
txt.y = y;
txt.text = text;
txt.setTextFormat(tFor);
addChild(txt);
}
Maybe attribute values must be obtained through the special features, but in the book K.Muka "ActionScript 3 for fash" says that it is necessary to do so. Please help me to solve this. Thanks in advance.
Well it's simple.
Flash is focused on the Internet, hence such problems.
If you wrote loader.load (urlR); it does not mean loaded. Accordingly, prior to the event confirming the end of loading, in loadare Null
if, instead of certain functions would be more code that would perhaps tripped your approach.
Yeah plus still highly dependent on the size of the file that you read.
Well, in general it all lyrics. Listen event on loader.contentLoaderInfo.addEventListener (Event.INIT, _onEvent), onEvent and read properties.
You need to wait for your image to load to be able to get values out of it.
Attach an eventListener to your URLLoader.
var urlR:URLRequest = new URLRequest("Image.jpg");
loader.load(urlR);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
function loader_complete(e:Event): void {
// Here you can get the height and width values etc.
var target_mc:Loader = evt.currentTarget.loader as Loader;
// target_mc.height , target_mc.width
}
Loader

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

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

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;
...