4 Replies Latest reply on Sep 21, 2010 1:22 PM by MageshR

    Loading Fonts from diff domain

    MageshR Level 1

      Hi - When I try to load fonts from a diff domain, it loads but when I call a font.regiserfont, it throws a AS error.

       

      In the main application, this is what I do to load the fonts.

       

      var loaderContext:LoaderContext = new LoaderContext();
      loaderContext.checkPolicyFile = true;

       

      var testFontloader:Loader = new Loader();
      testFontloader.contentLoaderInfo.addEventListener(Event.INIT, function(e:Event):void{
           var FontLibrary:Class = e.target.applicationDomain.getDefinition("testFont") as Class;
           Font.registerFont(FontLibrary.font);
      });
      var testFontReq:URLRequest = new URLRequest(model.serverLocation + ServiceURLConstants.ASSETS_PATH+"/embeddedFonts/testFont.swf");
      testFontloader.contentLoaderInfo.addEventListener(Event.COMPLETE,CheckFontLoadComplete);
      testFontloader.load(testFontReq,loaderContext);               

       

      And it throws an exception while it tries to register the font and it does not register it acutally. The main app is in code domain (domain1) and font swfs were placed in content domain (domain2)

       

      Error is:

       

      ArgumentError: Error #1508: The value specified for argument font is invalid.
           at flash.text::Font$/registerFont()
           at MethodInfo-778()

       

      I tried wih diff options, as to set loaderContext.checkPolicyFile = false; but they did not bear any fruit.

       

      This is the code to acualy embedd the font.

       

      package
      {
           import flash.display.Sprite;
           import flash.system.Security;
           import flash.text.Font;
          
           public class testFont extends Sprite
           {
               Security.allowDomain("*");
               [Embed(source="/fonts/testFont.ttf", mimeType="application/x-font", fontName="testFont",
                   unicodeRange="U+0020-U+007F,U+00A0-U+00A3,U+00A8-U+00AB,U+00AE,U+00B4,U+00B8,U+00BB,U+00B F-U+00CF,U+00D1-U+00D6,U+00D8-U+00DC,U+00DF-U+00EF,U+00F1-U+00F6,U+00F8-U+00FC,U+00FF,U+01 31,U+0152-U+0153,U+0178,U+02C6-U+02C7,U+02DA,U+02DC-U+02DD,U+2013-U+2014,U+2018-U+201A,U+2 01C-U+201E,U+2022,U+2026,U+2030,U+2039-U+203A,U+20AC,U+2122,U+FB01,U+FB02", embedAsCFF="true")]
               public static var font:Class;       
           }
      }

       

      Can someone guide me on what am I doing wrong? or is it possible at all to load and register fonts from a diff domain at all? Pls let me know if you need more info. Pls treat it as urgent!!