Bold and regular font in dynamic text under a mask In Flash with AS3 - html

I have this text "my text is <b>bold</b> and regular".
I want "<b>bold</b>" to be... well, let's say... bold !
I have a mask layer under which there is a text field.
The text field shows htmlText, and i must embed chars. If not embedded, it doesn't display because of the mask. So the solution of importing 2 user fonts ( one bold and one regular) does not work.
I'm thinking this is impossible to do with Flash... Maybe I wrong, am I ?
Thank you !

The problem is that when you embed the characters, it only embeds normal-weight font characters. The Mask is a red-herring; this will happen whether you mask the TextField or not.
You can solve the problem however! Create another TextField in your FLA (off-stage, I imagine) with the same font at the same size, but set the font to bold. Embed characters in that TextField too.
Then, the bold characters in your first TextField will display as bold.
There are other ways to achieve this, especially if you don't use the Flash IDE to compile your swfs (if you use MXML through FDT, FlexBuilder, FlashBuilder or FlashDevelop for example). If you do, then you should lookup how to embed fonts using [Embed] metadata.

Related

if statement skipped , uppercase letters not displaying

I'm making a mini game for my multimedia class using Adobe Animate with ActionScript 3.
The first question requires the user to fill in the blanks to print "hi" like in python.
the question looks like this
_____("hi")
then you would fill in the blanks and click on a check answer button.
Then to check if the answer is correct I use an if-else statement like so :
import flash.events.MouseEvent;
stop();
checkBtn1.addEventListener(MouseEvent.CLICK, checkClick);
function checkClick(event:MouseEvent): void
{
if(input1.text == "print")
{
ans1.text = "Correct!";
}
else
{
ans1.text = "Wrong answer!";
}
}
However, even if the input is correct, it will skip the if part of the code and run straight into else.
It also won't display uppercase letters?
It'll display "rong answer!" ignoring the uppercase "W".
Any ideas?
#Organis is right; The font needs to be embedded.
Flash Professional CS5 (and later) automatically embeds any characters used by text fields on the Stage. However, if you are using Dynamic or Input text fields, the project may also need to include characters for the font that aren't specifically contained in instances on the Stage during authoring. If you do not embed the necessary characters and text elements are programmatically displayed or entered by the user, the characters may be missing and the application may appear broken.
Common Mistakes Working with Fonts and Text Objects in Flash
For help embedding fonts, refer to the Adobe documentation on it.
Embedding Fonts with ActionScript
Embedding Fonts in Adobe Animate (Flash)

Actionscript 3 loading Chinese symbols into TextField using Actionscript

I am having trouble loading Chinese Symbols into a TextField from another TextField.
I have a dynamic drop down box that loads its text from a string within the actionscript code, however the actionscript code cannot contain chinese symbols.
I thought the easiest way around this problem would be to load the text from another TextField, however it seems to appear blank, failing to load the text.
example
base1_mc.header1.textbox_txt.text=q1.text;
base1_mc.header1.textbox_txt.text = dynamic drop down textbox.
q1.text = chinese symbols inside TextField on the stage.
I thought this would have been a simple problem, however it doesnt appear to be so.
If I try to load it using this
base1_mc.header1.textbox_txt.text=q1;
it loads some text declaring a new and empty function.
Can anyone help me out here?
Try to turn off embedFonts for TextField. I.E.:
textbox_txt.embedFonts = false.

AS3 textformat, embedfonts and multiple fonts?

Here is my issue : I have a dynamic html text field, to which i passed html text / textformat such as :
<P ALIGN="LEFT"><FONT FACE="Trebuchet MS" SIZE="14" COLOR="#000000" LETTERSPACING="0" KERNING="0">Some text<B>some bold text</B><I><U>and some italic underline</U></I></FONT></P>
My problem is, i can't use embedfonts because if i do, and use Trebuchet MS for instance, the bold tag will never render as in flash you have to select if the font your embed is bold or not. I'm trying to avoid to convert the whole htmltext/textformat thing to a CSS one..
Any ideas?
You need to make sure all versions of the font (regular, bold, italic, whatever) have been compiled into the SWF.
An easy way to do this is to create some dynamic TextFields (one for each version of the font you want to embed) and place them on stage somewhere out of sight at the start of your movie (for example on the root timeline, frame 1, at x = -100). Make sure they appear in your movie before you display the rest of your text, and make sure you embed the relevant character ranges.
This forces Flash to compile all versions of the font, not just the version you happen to have in your actual TextField you want to display.

TextLayoutFormat, when using embedded fonts, FontWeight property does not work

I have replaced all TextField objects with TextLayout as I require the functionality it offers. When using TextLayoutFormat I try to embolden text using "this._textLayoutFormat.fontWeight = FontWeight.BOLD;"
Adobe have said you can only embolden text when using device fonts:
"Applies only to device fonts (fontLookup property is set to flash.text.engine.FontLookup.DEVICE)."
This seems crazy to me! Does anyone know of a work around?
You have to embed your font twice: once with a normal weight "myFont" and once with fontWeight=bold "myBoldFont", then you should be able to switch from normal to bold by changing the fontName of your TextField. I do agree, this is stupid.

ActionScript 3 & font embedding

I have a problem with doing proper font embedding in a actionscript 3 project (flash CS4, not flex).
I followed this Adobe guide to do font embedding:
http://www.adobe.com/devnet/flash/quickstart/embedding_fonts/
the guide tells to set the Textfield.embedFonts property to true. if I do so and try to display a text with another font in this textfield, then nothing is displayed - that's fine, i expect it like this.
But now I have this particular problem:
i embed the font "Arial" in Regular style and create two input Textfields on the stage. one of them i set the embedFonts property to true (as described in the guide) the other i leave as is. Now I publish the thing as swf and try to enter the following (Turkish) string into the textfield
Yeni Yılın Barış ve Mutluluk Getirmesini Dileriz.
now the problem is, that the untouched textfield displays the string correctly - but the one with embedFonts set to true is missing some of the letters (for example ş is not displayed). But the Arial font does have this letter since it is displayed correctly in static - so why does it not render correctly when i set this property (as told in the guide)?
in my final app there shall be a single textField, but multiple embedded fonts and a way to switch between them (for example the user must be able to choose another font for entering chinese text).
can someone tell me how to do it properly?
thanks!
Embedding fonts in Flash is not as straight forward as it should be, and there are a bunch of special cases... One way to ensure that you are embedding the correct characters of your font is enabling "Generate size report" in the Flash Publish Settings.... there you will see all characters of all fonts that are being embedded. The only exception is that fonts embedded using the [EMBED tag do not show there.
Adding the font to the library doesn't embed the whole set of characters of that font (Arial for instance is about 8mb)... it only embeds a subset of them... I'm not sure if its always the standard occidental Latin set, or if it depends on the computer language.
You can extend this set manually using any textfield in your movie (with the "Character embedding..." dialog) as long as you use the actual Library Font name (it shows in the font list with an asterisc at the end... in your case it would be "Arial*").
You can also use the [EMBED tag with the unicodeRange to declare de character set, but bare in mind that the fonts you declare there wont be available in the Flash IDE during editing time... you need to set them at runtime with ActionScript (TextFormat, StyleSheet, etc...), which is not very practical when working with Flash.
I use the system fonts, and avoid the embedded ones like Arial.
public function get availableFonts(): Array
{
var font: Font = null;
var allFonts: Array = Font.enumerateFonts(true).sortOn("fontName", Array.CASEINSENSITIVE);
var embeddedFonts: Array = Font.enumerateFonts(false);
var excludeList: Object = {}
for each(font in embeddedFonts)
{
excludeList[font.fontName] = '';
}
var ourFonts: Array = [];
for each(font in allFonts)
{
if (!excludeList.hasOwnProperty(font.fontName))
{
ourFonts.push(font);
}
}
return ourFonts;
}
The list of fonts that this returns are going to have all their letters.
(wouldn't it be nice if ActionScript had some easier way of doing set difference built in?)
If you're looking for a more robust font loading solution that can load the different fonts at runtime, I've posted some code here (http://labs.tomasino.org/2009/07/16/flash-as3-runtime-font-manager/) and explanations of how to use it.