ActionScript Dynamic HTML Text With Embedded Fonts? - actionscript-3

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");

Related

Formatting Dynamic textfieldtype.DYNAMIC in AS3

Hi I am trying to format a textfield called myResult with the following code. It seems to have no effect on the size or type of text when I attempt it. Is there another way to format the textfield or am I missing something. The textfieldtype is DYNAMIC as it is displaying a result. Here is the code I am using
var myFormatA:TextFormat = new TextFormat();
myFormatA.color = 0xAA0000;
myFormatA.size = 28;
myFormatA.italic = true;
myFormatA.align = TextFormatAlign.CENTER;
myResult.setTextFormat(myFormatA);
use defaultTextFormat to apply a default format to any text that will be displayed (in the future if you will) in your textfield. Use setTextFormat to format the text that is currently displayed in your textfield. This is an important difference.

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.

Embedded fonts not appearing in actionscript created textfields

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

AS3 htmlText is showing tags

I have a textfield created with AS3 as thus: (theDesc is a parameter passed through a function)
var productDescTxt:TextField = new TextField();
productDescTxt.htmlText = theDesc;
productDescTxt.multiline = true;
productDescTxt.wordWrap = true;
productDescTxt.embedFonts = true;
productDescTxt.setTextFormat(productInfoTF);
productDescTxt.x = 10;
productDescTxt.y = productNameTxt.y+productNameTxt.textHeight+15;
productDescTxt.width = 325;
holder.productsTab.addChild(productDescTxt);
theDesc is html content with character encodings:
ex:
<p><strong>6.1 oz cotton at an affordable price</strong></p>
the problem is the textField is displaying every character. <p><strong> etc.
Is there any extra encoding need done on my end?
Looks like you get it from some server, don't you? You need to change < with <, > with > manually. E.g. in PHP (if server part of your app is written on PHP) there's html_decode() function which will replace all for you. I don't know of similar function in AS3.
But, I can advise you small trick:
var tempField:TextField = new TextField();
tempField.htmlText = theDesc;
var productDescTxt:TextField = new TextField();
//...
productDescTx.htmlText = tempField.text;
holder.productsTab.addChild(productDescTxt);
that will do html_decode() for you! hope that helps!
view source of this page and find this line:
<weare the something>
this answer box does almost the same as flash textField htmlText function.
more about htmlText posibilieties in flash: TextField – available html tags
You don't want HTML special characters for the htmlText value, escape them see this answer Unescape (decode) HTML characters from string in Flex

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?