Embedded fonts not appearing in actionscript created textfields - actionscript-3

I would like to preface this wall of text by saying, I am very new at this. I may be missing something obvious.
I'm working in Flash CS5 with Actionscript 3. I'm trying to use actionscript to create a textfield, and populate it with text. I've embedded my font in my project using the "Font Embedding" window. However, when the code to create the textfield is run, if "embedFont = true;", the font is invisible. The cursor still changes when hovering over it, so I know it's there. Or at least its text box is, I guess. Dynamic textfields with embedded text which are already on the stage seem to be unaffected.
I've tried changing the embedded fonts outline format, neither work. I've tried directly embedding the font with the "embed" tag via actionscript, but it doesn't seem to work with CS5, or I don't know what I'm doing. As you can see in the code provided, I've tried "registering" the font, with no success. I've tried using:
var font:Font = new screenfont(); //"screenfont" is the name from Embedding Fonts
var format:TextFormat = new TextFormat();
format.font = screenfont.fontName;
No dice.
I've followed some different tutorials about embedding, and come across a wealth of conflicted, confusing information. I've read a few different posts pertaining to this subject, but haven't found any viable solutions as of yet.
Here's a simple version of my code, where "screenfont" is the name I specified in the Embedding Fonts window:
Font.registerFont(screenfont);
//TextFormat
var listformat:TextFormat = new TextFormat();
listformat.align = TextFormatAlign.LEFT;
listformat.size = 20.8;
listformat.color = 0x0DAC54;
listformat.font="Fixedsys Excelsior 3.01";
//TextField
var photolist:TextField = new TextField();
photolist.x = photos_x;
photolist.y = tempY;
photolist.width = photos_wdth;
photolist.height = photos_hght;
photolist.text = photoname;
photolist.embedFonts = true; //<--- This freakin' guy!
photolist.antiAliasType = AntiAliasType.ADVANCED;
photolist.defaultTextFormat=listformat;
photolist.selectable = false;
photolist.wordWrap = true;
mediapage.photos.addChild(photolist);
I hope this provides a clear picture.
So, how exactly is embedding accomplished in CS5?

You should set the text as the last thing you do. So this line photolist.text = photoname; should be after everything else.
var photolist:TextField = new TextField();
photolist.x = photos_x;
photolist.y = tempY;
photolist.width = photos_wdth;
photolist.height = photos_hght;
photolist.embedFonts = true;
photolist.antiAliasType = AntiAliasType.ADVANCED;
photolist.defaultTextFormat=listformat;
photolist.selectable = false;
photolist.wordWrap = true;
photolist.text = photoname;//<-- set text only after applying all formatting and embedding
mediapage.photos.addChild(photolist);

Related

How to use a font embedded in a SWC

I exported a SWC from Flash CS3 with a font embedded.
Now I want use it in some TextFields, but I don't know how to use the font.
Done! Here's my solution:
[Embed(source="res/guardanapo.otf", fontName="guardanapo", fontFamily="guardanapo", unicodeRange="U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E", advancedAntiAliasing="false", embedAsCFF="false")]
public static const fonte:Class;
I wanted to embed the font from SWC, but now it isn't necessary anymore. But answer if you know how to do that, maybe someone is serching for it now.
Give this a try. myLoader is the loader that you loaded your swf/swc with the font in its library. myTextField is a pre-existing text field. I set embedFonts to true, but you may not need it.
var MyFont:Class = myLoader.contentLoaderInfo.applicationDomain.getDefinition("FontClassName");
var embeddedFont:Font = new MyFont();
var textFormat:TextFormat = new TextFormat();
textFormat.font = embeddedFont.fontName;
textFormat.size = 24;
myTextField.setTextFormat(textFormat);
myTextField.embedFonts = true;
Maybe you can include a font-fetching class in the swf with the font(s) you want to use. There could be static methods that apply a font to a field, or return the font name given the font's class name. This could help keep the rest of your application cleaner.

Actionscript 3.0 Embed Font - Text Not Appearing

I am creating dynamic TextFields in actionscript 3.0. Like many others, my text disappears when I set .embedFonts = true;
ArialSlim is embedded and exported for actionscript. I have successfully tested with trace(Font.enumerateFonts());
Interestingly enough, when I comment out the embed line (as shown below), the font works properly.
Alternatively, .setTextFormat(); also works properly without the .embedFonts line.
So my questions is, why? Will I run into any issues in this case?
var divArray = new Array();
var x_Lbl_Array:Array = new Array();
var entries:int = 10;
var labelFormat:TextFormat = new TextFormat();
var arial:Font = new ArialSlim();
labelFormat.font = arial.fontName;
labelFormat.size = 10;
var xVar:int = 0;
for(var loop:int = 0; loop < entries; loop++){
x_Lbl_Array[loop] = new TextField();
//x_Lbl_Array[loop].embedFonts = true;
x_Lbl_Array[loop].antiAliasType = AntiAliasType.NORMAL;
x_Lbl_Array[loop].defaultTextFormat = labelFormat;
x_Lbl_Array[loop].x = xVar;
x_Lbl_Array[loop].y = 165;
x_Lbl_Array[loop].text = "test";
mc.addChild(x_Lbl_Array[loop]);
xVar++;
}
Edit:
I just ran this code from frame 1 with .embedFonts = true; and it worked...
Maybe I should mention that I'm having trouble running this code in a method inside an instantiated actionscript class. The class is located in an external .as file. Does this help answer my question?
I tried your code and it worked for me (with the embedded font)
check if you have all the characters included.
You can either set the character range, or create a textfield that has all the characters.
It turns out that I at some point clicked "TLF (DF4)" in the outline format options for my embedded font. When I corrected this, and chose "Classic (DF3)," it fixed my problem.
I guess what I find to be really weird is that the font was showing properly without .embedFonts being set to true
Thank you, Daniel. I appreciate the help.

AS3: Embedding characters

I having some trouble with TextFields and caracter embedding. As I have understood, the way to embed character in Flash, is to have a TextField in a movieclip that is exported to actionscript via some classname. Then have the TextField embed the characters.
But when i try to use that TextField in my project, I cannot auto resize the field any longer!? Is there a better way to embed charactes? or am I missing some unknow attribute? (and yes i have tried TextField.autoSize = "left" (or "center" or "right")).
The TextField is configured like this in Flash CS4:
Properties:
http://screencast.com/t/0VB6KnNO6G
Library implementation:
http://screencast.com/t/w3yQLqit0veI
And I embed the MovieClip containing the TextField like this:
protected var tabname:MovieClip = new Text(); // The property on the object
Adding the text and setting its Settings:
var txt:TextField = tabname.txt;
if( !contains(tabname) )
{
addChild(tabname);
var format:TextFormat = new TextFormat();
format.bold = true;
format.font = "Arial";
format.size = 12;
format.align = "left";
var dropShadow = new DropShadowFilter(0);
dropShadow.color = 0xFFFFFF;
dropShadow.strength = 2;
dropShadow.blurX = dropShadow.blurY = 5;
dropShadow.alpha = .7;
txt.type = TextFieldType.DYNAMIC;
txt.multiline = tabname.wordWrap = false;
txt.autoSize = TextFieldAutoSize.LEFT;
txt.defaultTextFormat = format;
txt.filters = [dropShadow];
txt.mouseEnabled = false;
txt.x = 10;
}
txt.text = value;
txt.y = Math.ceil((tabmask.height - txt.height) /2);
To embed fonts, don't rely on wrapping them in MovieClips in the library. They should be embedded correctly as Fonts. I have included some basic steps below for embedding fonts, then an example for your particular situation:
1 - Make the textfield Dynamic and click the Embed.. button
2 - Name the font with something meaningful (like the fonts name) and tick the character sets you will be using (usually I select caps, lowercase, numbers and punctuation). Also note the Style is 'Bold', you will need to embed a font set for each style. So if you want to use Bold and Regular, you need to embed 2 fonts.
3 - If you plan on adding textfields dynamically through ActionScript, goto the ActionScript tab and add a class for it (again, use a meaningful name)
4 - Finally click ok, and away you go. I have setup an example, using these steps, and the auto size method, you can see the results below
In Flash, you can click the [Embed...] button below the TextField's character properties. In the window that you get then, you can specify which characters you want embedded in your textfield.
There's a lot more to say about font embedding but this is the simple story. Flash CS5 added TLF TextFields but I don't think you were referring to those, right?
The autoSize property really has nothing to do with font embedding but I guess your TextField is not Dynamic when you cannot auto resize it?
Are you using CS5 or CS4 or earlier by the way?

ActionScript Dynamic HTML Text With Embedded Fonts?

i'm trying to use htmlText on a dynamic text field with embedded fonts. i've searched for an hour for an answer and i still don't have one.
on stage, there is a dynamic text field with no text. i've embedded both regular and bold versions of Myraid Pro. the text field on stage is set to regular (have to choose something). "Render Text As HTML" is selected.
the following code in my document class doesn't work:
myText.autoSize = TextFieldAutoSize.CENTER;
myText.htmlText = "Not Bold <b>Bold</b>";
the html tags only work if the text field on stage is set to "use device fonts" in the anti-alias setting.
unreal.
It may be your embed parameters missing embedAsCFF='false', try something like:
[Embed(source='path/to/foo.otf', fontName='foo', embedAsCFF='false')]
In flex 4 the default is true to take advantage of the new text engine while flash.text.TextField relies on the old engine. There's more details here.
Well i have faced this problem. i forgot the solution but i have clue for you.. Try this way
var myFormat:TextFormat = new TextFormat();
myFormat.font = "Arial";
myFormat.size = 14;
myText.autoSize = TextFieldAutoSize.CENTER;
myText.defaultTextFormat = myFormat;
myText.embedFonts = true;
myText.htmlText = "Not Bold\n";
myText.appendText("Bold");

flex: Create a screenshot of UI element

I want to make a screenshot of custom as3 ui element (which was extended from Canvas), and then upload the image on the server.
Could you help me with a small example of this?
I am trying to do the following:
// This is UI component extended from Canvas
var chessBoard:ChessBoard = new ChessBoard();
// I displayed pieces on the board, but didn't add it to the stage (I just need a
// a screenshot, not need them on the canvas)
chessBoard.displayPosition(DataStorage.getInstance().getStoredPosition(0));
var img:ImageSnapshot = ImageSnapshot.captureImage(chessBoard, 300, new PNGEncoder());
var obj:Object = new Object();
obj.complexity = complexity.value;
obj.img = img;
httpService.send(obj);
and getting this error:
ArgumentError: Error #2015: Invalid
BitmapData. at
flash.display::BitmapData() at
mx.graphics::ImageSnapshot$/captureBitmapData()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\graphics\ImageSnapshot.as:186]
at
mx.graphics::ImageSnapshot$/captureImage()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\graphics\ImageSnapshot.as:282]
at
ui::SendForm/send()[/Users/oleg/Documents/chess_problems/problemme/src/ui/SendForm.mxml:53]
at
> ui::SendForm/___SendForm_Button1_click()[/Users/oleg/Documents/chess_problems/problemme/src/ui/SendForm.mxml:16]
This error was caused by missing width and height of the Canvas. I set them and it helped to create bitmap data this way:
var bitmapData:BitmapData = new BitmapData(chessBoard.width,chessBoard.height);
var encoder:PNGEncoder = new PNGEncoder();
var data:ByteArray = encoder.encode(bitmapData);
I wonder how do I send the image to the server via httpService? Is there a way. Also is data = image file?
Here is a post on someone who has done this exact thing in AS3:
Dynamically Create an Image in Flash and Save it to the Desktop or Server
It is possible, and although I have never done it, this may be useful to you: http://www.flash-db.com/Tutorials/snapshot/