Using embedded fonts in Flash CS3 using ActionScript 3
I just thought I'd make a quick post about how to use embedded fonts in Flash CS3 using ActionScript 3 because I had to do that last week and I did really know how to do it. Well it starts just as you did in Flash 8, you right click in the library and you choose New Font... Then choose the font you want to embed and click Ok. Now you'll have to right click on the new font in the library and choose linkage. In the pop window, click export for ActionScript and give it a class name. Once that is done you can use that font in any textfields you create with ActionScript.
Here is code showing you how to do it:
-
var helve:Font = new Helve();
-
buttonLabel = new TextField();
-
txtFormat = new TextFormat();
-
txtFormat.font = helve.fontName;
-
txtFormat.color = 0x000000;
-
txtFormat.size = 14;
-
buttonLabel.embedFonts = true;
-
buttonLabel.text = "place label text here";
-
buttonLabel.setTextFormat(txtFormat);
My font class name in the library was Helve. I use the TextFormat object to set the font for the textfield, it's that easy.
March 27th, 2008 at 10:54 pm
where your class?
April 19th, 2008 at 3:06 pm
Thank you!
April 25th, 2008 at 2:11 pm
Thanks, this was a lifesaver :]
July 8th, 2008 at 9:36 pm
Thanks. Helps a lot.
Roy, his class is in the first line.
July 24th, 2008 at 10:19 pm
The class is *not* in the first line. An instance of the Helve Class is created on the first line.
The class is generated automatically by Flash when the .swf is compiled. The author wrote: “In the pop window, click export for ActionScript and give it a class name.” When you close the linkage dialog, Flash will tell you that it can’t find the specified class, but it will kindly create it for you on compilation. The generated class is then embedded into the .swf, but unless you decompile it, you’ll never see it…
August 13th, 2008 at 4:49 pm
Wish I found this 2 hours ago - thanks though I think this should read as having the var and class named the same caused an error
var _helve:Font = new helve();
var buttonLabel = new TextField();
addChild(buttonLabel)
var txtFormat = new TextFormat();
txtFormat.font = _helve.fontName;
txtFormat.color = 0×000000;
txtFormat.size = 14;
buttonLabel.embedFonts = true;
buttonLabel.text = “place label text here”;
buttonLabel.setTextFormat (txtFormat);