2 Replies Latest reply on Mar 29, 2012 6:28 PM by yanpan

    Trouble in loading external swf file and embedded font dynamically

    yanpan

      I have developed a flex application doing something like this: it loads A.swf from somewhere and show it on the stage

      sometimes A uses fonts not installed on users' machine, so at this time my app will load B.swf with needed fonts embedded in it from another place

      I have working it out that fonts in B.swf can be detected and shown in my app stage, but when I use SWFLoader to show A.swf, it still fails in showing the fonts properly...

      Some of my codes pasted here:

       

      // load fonts

       



      private function onFontBytesLoadComplete(e:Event):void {



      var data:ByteArray = e.target.data as ByteArray;







      swfLoader.addEventListener(Event.COMPLETE, onSWFLoadComplete);



      swfLoader.source = data;


      }





      private function onSWFLoadComplete(e:Event):void {



      loadSM = SystemManager(swfLoader.content);



      loadSM.addEventListener(FlexEvent.APPLICATION_COMPLETE, onFontLoadComplete);


      }

       



      private function onFontLoadComplete(e:FlexEvent):void {



      var clazz:Class = loadSM.loaderInfo.applicationDomain.getDefinition(fontName) as Class;



      var fun:Function = clazz.getFont as Function;



      var fontClazz:Class = fun();



      var font:Font = new fontClazz() as Font;



      trace(getQualifiedClassName(new fontClazz()));



      Font.registerFont(fontClazz);



      if(loadFinishedHandler != null) {




      loadFinishedHandler(fontName);



      }


      }

       

      Anyone has idea about this? 3x~