Guerreiro
Guerreiro

Reputation: 133

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.

Upvotes: 3

Views: 1512

Answers (2)

Guerreiro
Guerreiro

Reputation: 133

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.

Upvotes: 2

mfa
mfa

Reputation: 5087

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.

Upvotes: 0

Related Questions