Tuesday, March 29, 2005
This is really a reminder to myself and might help a few people who are making the same mistake I always make. When you dynamically create a textfield using MovieClip.createTextField() you have to do a couple of things in order to get the correct font to appear. First you need to add a new font to your library and give it a name (eg. "someFont"), then and this is the bit I always miss, you have to right click on the font symbol in your library and select linkage and select Export for actionscript.Finally you need to setup a TextFormat object in your code:
var my_fmt:TextFormat = new TextFormat();
my_fmt.font = "someFont";
my_txt.setTextFormat(my_fmt);
All sounds pretty obvious doesn't it, but I always make the same mistake and think that just because I have given the font symbol a name that I don't have to add a linkage id!
Jon 11:16 AM Permalink
Comments:
Yeah, i hope they fix that smidgin of the interface in the next version of flash. With movie clips you can select export for actionscript from the properties, but with fonts you have to hit linkage.
Even when I do all of this I find sometimes it just doesn't want to play nicely!
i wouldn't export the flont as a symbol in your library. There's a whole plethora of characters that you will more than liekly never use that will just add unnecessary bloat to your file size.
Just place a text field on the stage embed the characters you'll need. Then use the name of the font in that text field for the myTextFormat.font setting (and make sure you set the myTextField.embed property to true).
I understand what you are saying about bloating the file size, but I am dynamically adding textFields as a list of questions and comboBoxes depending on what is in an XML file, there could be 10, there could be 50 so adding them to the stage is not an option, also I have no idea what font symbols I am going to need so this way is much safer for application development I'm sure you will agree?


