PDA

View Full Version : Font embedding


Doccie
11-01-2008, 10:36 PM
So, I tried this in different ways, but nothing seems to have worked so far.

I have a movieclip containing a vector and in it I want to place a label. I linked this movieclip to a class. The movie is supposed to be scalable, so I can't just add a textfield with embedded fonts to the movieclip in the library, since it would stretch.

That's why I want to add the textfield dynamically through the class constructor. I created a font symbol in the library, but I can't quite figure out how to import and use the font in an external class.

edit: I'm not using Flex, just AS3. So [Embed] won't work :)

Doccie
11-02-2008, 12:46 AM
Sooooo... I found a rather involved solution. If there are better ones, I'd love to hear them, but this is what I came up with.

I created a new .fla file, opened the library and added the font to the library. Then, I linked it to a class 'MyFont'. I placed this actionscript on the first frame of the movie:

function getFont():Font {
var my_font:Font = new MyFont();
return my_font;
}

Then I created a class FontLoader which basically loads that SWF using the Loader class and when it is loaded, it calls the getFont function from the loaded swf and stores the font in a private variable.

It then dispatches a custom event (FontEvent.LOADED) to the class which initiated FontLoader. The listener receives the notification and uses a getter from the FontLoader class to retrieve the embedded font.