1 Reply Latest reply on Jan 25, 2011 9:14 AM by Ninarama

    Embedded fonts dissapear (a bit complicated, read on...)

    Ninarama Level 1

      This is the actual case:

       

      There is an SWF which contains just a font to be used by many other SWFs, it is here:

       

      ./SharedRessources/ComicFont.swf

       

      Then there is one SWF which imports this font for runtime use:

       

      ./Selector/Selector.swf

       

      And another one which also imports this font for runtime use:

       

      ./Menu/Menu.swf

       

      They both import the font "for runtime use" and this, relative path: "../SharedRessources/ComicFont.swf".

      This works for both Selector.swf and Menu.swf quite well. The font is displayed correctly.

       

      BUT now there is this one:

       

      ./Everything/Everything.swf

       

      This one loads Selector.swf and Menu.swf BOTH. The result is: The embedded font dissapears!

      The funny thing: If I only load ONE of them, the font is visible.

       

      So: Having 2 SWFs loaded simultaneously which make use of a font which is "shared for runtime use" destroys it for both.

       

      Anyone encountered this problem yet? Any simple workarounds? The not-so-simple workaround would be to do it all directly via Actionscript and letting the Container hold all the ressources. But this would just be very comfortable.

      OR could this even be filed as a bug?

        • 1. Re: Embedded fonts dissapear (a bit complicated, read on...)
          Ninarama Level 1

          After fiddeling around with the code, I actually found a solution:

           

          The Font is embedded as a class, "ComicFont". So using the Loader class the usual way to load more than one module that uses this Font will cause the ComicFont class to be overwritten (and thus lost to the module loaded before)

          I ran a test like this for every module loaded:

           

          for each (li:LoaderInfo in loaderInfos) { // for simplicity: Imagine I have all LoaderInfos of all loaded submodules here

            trace ("Has class ComicFont? "+li.hasDefinition('ComicFont'));

          }

           

          Doing it the nomal, lazy way, this would output:

          Has class ComicFont? false

          Has class ComicFont? false

          Has class ComicFont? false

          Has class ComicFont? true

           

          So it seems just the last module actually contained the ComicFont class. No wonder the font disappeared for all the other modules.

           

          The "trick" was to set the applicationDomain inside the Loader:

           

          var ld:Loader = new Loader();
          var context:LoaderContext = new LoaderContext();
          context.applicationDomain = ApplicationDomain.currentDomain;

          ld.load(new URLRequest(swfName), context);

           

          Now the fonts appear in every module and the output of the loop above is:

          Has class ComicFont? true

          Has class ComicFont? true

          Has class ComicFont? true

          Has class ComicFont? true

           

          I hope this could help someone...