Categories Displayed in Flash

Flash and Fonts: Sharing Embedded Fonts with multiple swfs ( Font.registerFont to the rescue)

Yet another day in the trenches debugging Embedded Fonts this time, using Embedded Font Assets in the Library, with multiple swfs that are a hierarchy like:

  • mainSwfWithFonts.swf
  • child.swf
  • grandchild.swf

A zip of 3 Fla's for this is here embeddedfontsharingacrossswfs

Conclusion.

  • make sure your Library Embedded Font is set to export on frame1, and is checkmarked to export for actionscript.
  • make sure that you  "Font.registerFont(YourFontClassNameGoeshere);" else while child.swf can access it's parent's swf fonts without any issues, grandchild.swf will NOT be able to use the embedded font tables.
  • avoid static text fields, or dynamic textfields with partial embedded character sets in multiple swfs,..only one can be used, else they will collide, first takes all.  Say you have a static textfield with "Hi" past this no other swfs fonts can be used, meaning your pretty much stuck with the characters H and i.
  • if your font appears in "()" Flash could not find the font on your filesystem and is using a mapped font instead.  Make sure the font is correctly installed, close down all the Fla's and edit the font mappings ( Edit> Font Mapping).

Testing

Behavior,

create a Font name it "Finky".  Create a textfield on stage and choose the font "Finky*"   (it should not appear (Finky*)  Rotate that TextField a few degrees... this will be invisible on Flash 9.  Go back to the Library and delete the Finky Font.   Turn publish size report on, Test Publish you'll get an output like and a blank stage.

Font Name                 Bytes        Characters
----------------------    ---------    --------------
Finky* Bold                      16
Myriad Pro Bold          24621     ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Note that the name in the Textfield* is just an alias to the 'real font' it it finds it it will replace it.

Create the Finky library again. and republish, note no characters are embedded and it still doesn't show up.

Font Name                 Bytes        Characters
----------------------    ---------    --------------
FinkRoman Bold                   18
Myriad Pro Bold               24621     ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Now in the TextField, Choose to embed the UPPERCase in the Embed... option, republish you will only see the capital letters, because in this case it's pulling from the Textfield and not the one in the library. Note how it's handing things off.

Font Name                 Bytes        Characters
----------------------    ---------    --------------
Finky* Bold                    4595     ABCDEFGHIJKLMNOPQRSTUVWXYZ
Myriad Pro Bold            25338     ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Note in this case the memory jumps up a ton, this is likely the size of the font character set.

Font Name                 Bytes        Characters
----------------------    ---------    --------------
FinkRoman Bold                35261     ABCDEFGHIJKLMNOPQRSTUVWXYZ

Now in the library right click and select Export For Actionscript, and Export in firstframe. Test Publish, note now we get every character under the sun. and the text shows up in the main swf and the child swf but not the grandchild swf!

Font Name                 Bytes        Characters
----------------------    ---------    --------------
FinkRoman Bold                66175     !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿˆ˜–—‘’‚“”„†‡•…‰‹›€™
Myriad Pro Bold               25756     ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Now try going back to the textfield and choose something other than letters (e.g. punctuation) as to embed..normally this would make only punctuation show up, but since we don't have any we shouldn't expect to see anything. But SURPRISE, they all show up!  This means that the TextField has the key to the font table and whatever it contains.

Lastly now use Font.registerFont(Finky) and test again, viola now all 3 swfs have access to the fonts.

This took several hours to figure out.  I thought originally it was Security.allowDomain, or loading into the same ApplicationDomain since there are the same Font objects.... but nope.

TIPS

1) You can use the neato Array.filter to help trace the fonts. e.g.

  1. var embeddedFonts:Array = Font.enumerateFonts(false);
  2.  
  3. embeddedFonts.sortOn("fontName", Array.CASEINSENSITIVE);
  4.  
  5. trace("Found Embedded Fonts " + embeddedFonts.filter(traceFontName));
  6.  
  7. function traceFontName(cur:*, ...rest):void{
  8.  
  9. trace(cur.fontName);
  10.  
  11. }
  12.  

2) You CANNOT use that iterator to expose fonts automatically in the Font.registerFont, Font instances from embedded have abstract Class that can't apparently be referenced.

2 responses to 'Flash and Fonts: Sharing Embedded Fonts with multiple swfs ( Font.registerFont to the rescue)'

[...] Extern gefunden: Yet another day in the trenches debugging Embedded Fonts this time, using Embedded Font Assets in the Library, with multiple swfs that are a hierarchy like: mainSwfWithFonts.swf child.swf grandchild.swf A zip of 3 Fla’s for this is here embeddedfontsharingacrossswfs Conclusion. make sure your Library Embedded Font is set to export on frame1, and is checkmarked to export for actionscript. make sure that [...] via [...]

[...] > Flash and Fonts: Sharing Embedded Fonts with multiple swfs : TroyWorks [...]

Add a Comment: