Posted By

tuffstudio on 04/18/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

dstrystudio


AS3 recursive font embed


 / Published in: ActionScript 3
 

Well….the truth is: the way Flash deals with font managing just suck! Normally, you’ll have to export the font’s characters. To do this follow these steps:

On the Main Menu go to Text -> Font Embeding Click on the + thing and add a new font. Give a name to the font Select the font on the combobox, and select which group of characters to be exported. Tip: Be sure to select only the characters you’ll actually use (it doesn’t make sense to export Japanese characters to a brazilian website, right?), because flash will export them on the SWF and this will increase filesize.

  1. Go to the actionscript tab and select “Export for Actionscript”

Tip: This is actually optional, but if you are doing a lot of actionscript coding, it’s good to do this because you can use the font asset as an actionscript object and initialize with the new keyword and everything.

  1. Select the Textfield you want that font for and type the name of the font you set on step 3. Notice that Flash will put an * after the font name. This is just to identify the font as a library asset.

Now there’s the trick. For every dynamic textfield you have, you must set TextField.embedFonts = true to it’s instance.

  1. function recursiveEmbed(container : DisplayObjectContainer) : void
  2. {
  3. for(var i: int = 0; i < container.numChildren; i++)
  4. {
  5. var child : DisplayObject = container.getChildAt(i);
  6.  
  7. if(child is DisplayObjectContainer)
  8. recursiveEmbed(child as DisplayObjectContainer);
  9. else if (child is TextField)
  10. TextField(child).embedFonts = true;
  11. }
  12. }
  13. //// You can use it like this on your root movieclip or Document Class or whatever: //// recursiveEmbed(this)

Report this snippet  

You need to login to post a comment.