1 Reply Latest reply: Jul 11, 2013 1:55 PM by flexzionist RSS

    Loading font class fails when loader is being subloaded from app-storage://

    flexzionist Community Member

      Hi

       

      I'm developing a presentation that has to work on Web(Pure AS3), Desktop, Android and iOS.


      I make use of shared runtime fonts using same technique as illustrated here:
      http://www.scottgmorgan.com/runtime-font-embedding-in-as3-there-is-no-need-to-embed-the-en tire-fontset-anymore/

       

      Specifically:

      private function fontLoaded(event:Event):void { 
           var FontLibrary:Class = event.target.applicationDomain.getDefinition("_Arial") as Class; 
           Font.registerFont(FontLibrary._Arial); 
      }
      

       

      Problem when running in AIR:

       

       

      *AIR-SWF = SWF's compiled for AIR
      *AS3-SWF = SWF's compiled for FlashPlayer

       

      The AS3-SWF that loads the AS3-SWF-font is placed in the same domain as the AS3-SWF-font , namely app-storage://
      The AIR-SWF that loads the AS3-SWF - that loads the AS3-SWF-font.swf - is, naturally, running from app://

       

      So the scenario that fails is this:

      app://AppLoader.swf > app-storage://MainAppUIAndFunctionality.swf > app-storage://fonts/fNormal.swf

       

      When i'm testing my MainApp, just as test SWF's , just as regular web/html/flash.. it all works..
      But when my mainApp is being loaded by my AIR loader, it doesent work anymore.


      In the AS3-SWF's I've set communincation "Local Access" and applied System.allowDomain("*") which indeed makes me able to communicate both ways, all the way to the AIR-SWF (not directly, but by referencing objects/functions)

       

      So..no security errors, still I supsect sandbox/domain issue ^^..


      Any ideas how to make it work?

       


      Edit:

      After i try use:

      var FontLibrary:Class = event.target.applicationDomain.getDefinition("_Arial") as Class;
      Font.registerFont(FontLibrary._Arial);

      The error i get is:

      The value specified for argument font is invalid.

          at flash.text::Font$/registerFont()

        • 1. Re: Loading font class fails when loader is being subloaded from app-storage://
          flexzionist Community Member

          Solution found at: http://code.google.com/p/maashaack/wiki/ApplicationDomain

           

           

          var urlloader:URLLoader = new URLLoader();
                 urlloader
          .dataFromat = URLLoaderDataFormat.BINARY;
                 urlloader
          .addEventListener( Event.COMPLETE, onComplete );
                 urlloader
          .load( new URLRequest( "other.swf" ) );

          var onComplete:Function = function( event:Event ):void
          {
             
          var loader:Loader = new Loader();
             
          var AD:ApplicationDomain = ApplicationDomain.currentDomain;
             
          //with loadBytes(0 -- the checkPolicyFile and securityDomain properties of the LoaderContext object do not apply.
             
          //var SD:SecurityDomain    = SecurityDomain.currentDomain;
             
          var context:LoaderContext = new LoaderContext( false, AD );
                     context
          .allowLoadBytesCodeExecution = true;

              loader
          .loadBytes( urlloader.data, context );
          }