Wednesday, January 23, 2008

Embedding an Font in Flash/Eclispe

I have had a interesting time of trying to get an embedded font (In the Library of Flash) to be dynamically assigned to a created Dynamic Text Field.

Now in Flash (CS3) it looks like this
(In the Library, the Fonts Linakge class name is "BradyBunchRemastered")

var rewardTxtNew:TextField = new TextField();
var _textFormat:TextFormat = new TextFormat();
var tEmdFont:BradyBunchRemastered = new BradyBunchRemastered();

_textFormat.font = tEmdFont.fontName;

rewardTxtNew.defaultTextFormat = _textFormat;
rewardTxtNew.embedFonts = true;

Well In Flex 3 it looks like this
[Embed(source="c:/windows/fonts/BradBunR.ttf", fontFamily="Brady Bunch Remastered", fontName="BradyBunchRemastered")]
private var BradyBunchRemastered:Class;

var rewardTxtNew:TextField = new TextField();
var _textFormat:TextFormat = new TextFormat();
var tEmdFont:Class = new BradyBunchRemastered();

_textFormat.font = tEmdFont.fontName;

rewardTxtNew.defaultTextFormat = _textFormat;
rewardTxtNew.embedFonts = true;

But Now we get some wonderful compile Time Errors. Since Eclipse does not know what BradyBunchRemastered is it will throw an Error.

If you add a var to reference the font
public var BradyBunchRemastered:Font;

Then the compile errors go away but it does not work in flex.

Now you might ask why not just compile this in Flash or Flex and be done with it. Well as the Container.swf file that holds this application has a reference to the applications class file for correct typecasting and the Container.swf must be complied in Eclipse. The application has a timeline so it must be compiled in flash.

So what I have is a issue with the difference in coding for Flex VS Flash.

Any Ideas?

No comments: