7 Replies Latest reply on Apr 5, 2011 1:56 PM by eprevot123

    Embed Font and change textField font in different swf

    eprevot123 Level 2

      I have a problem with font embedding.

      I have a main application that loads dynamically some MovieClips which are in external swfs, and place them in a container. The main application embed font and change the textField font and text of the loaded movieclips.

      I can make it work on a simple example project with that code :

       

      [Embed(source="MyriadPro-Semibold.otf", fontName="font1", mimeType="application/x-font", embedAsCFF="false")]
      private const Font1:Class;
      ...

      Font.registerFont(Font1); //to share the font with movieClip in other swf

      ...

      var myformat:TextFormat = tf.getTextFormat();
      myformat.font = "font1";
      tf.embedFonts = true;
      tf.defaultTextFormat = myformat;
      tf.text = "abcdef";
      tf.rotation = 15; //just to test font is really embedded

       

      But in my real project the text does not appear, and tf.textHeight is 0, just like I didn't embed the font.

      I search for the difference between my test project and the complex one but I can't find it.

      Do you think it could be an applicationDomain problem ?

      Have you experienced some problem with font embedding, can you give me a clue ?

       

      Note that I can use the embedded Font in my main application, to display a new TextField for example. I just can't modify the TextField nested in the loaded swf.

        • 1. Re: Embed Font and change textField font in different swf
          eprevot123 Level 2

          My application is like this :

          View1 contains View 2 (or View 2b depending on the state)

          View 2 loads the swfs that contain movieClips. View 2 contains View 3 (or View3b depending on the state)

          View 3 contains View 4.

          View 4 embed the font, instanciate movieclips from the loaded swfs, and change the font and text of the textfield in the movieClips.

           

          Should I embed and register the font in each view ? or is it ok to do it only on View4 ?

          • 2. Re: Embed Font and change textField font in different swf
            eprevot123 Level 2

            I just see the difference between my test project and my real application :

            - In my test project I have one swf containing a MovieClip in the source package. I load the swf from the local package, and then I can use an embedded font.

            - but in my real application, MovieClip swfs are in an other directory in my machine. When I load them from that directory, I can't use embedded font in them.

             

            Do you know what I miss to be able to use embedded font in the loaded swf ?

             

            I thought Font.registerFont(myEmbeddedFont) was enough to allow the loaded swf to use myEmbeddedFont...

            • 3. Re: Embed Font and change textField font in different swf
              Flex harUI Adobe Employee

              If the sub-swfs are being loaded into different security sandboxes, then

              maybe registerFont won't work.  Otherwise, it should.

              • 4. Re: Embed Font and change textField font in different swf
                eprevot123 Level 2

                I load the same way for the 2 projects, the only difference is the location of the swf I load. I don't know much about securityDomain...

                I load that way :

                 

                var url:URLRequest = new URLRequest("myMovieClip.swf"); //can embed font in this case

                or

                var url:URLRequest = new URLRequest("file:///the/path/to/file/myMovieClip.swf"); //can't embed font in this case

                 

                var loaderCtx:LoaderContext = new LoaderContext(false);
                loader.load(url,loaderCtx);

                • 5. Re: Embed Font and change textField font in different swf
                  eprevot123 Level 2

                  I made some tests, if I use the URLRequest with :

                  file:///path/to/my/project/sources/myMovieClip.swf --> it works

                  ../../../path/to/my/desktop/myMovieClip.swf --> it does not works

                   

                  so it does not come from the use of "file://" or a relative path. The font that I registered in my main application can be used in the swf that are in the same location than my application. But I can't use that font if the swf is out of my project (on my desktop or another directory).

                   

                  I may add that it is an Air application.

                   

                  As a workaround I could copy all the swf in my project but the problem is that those swfs are used by several projects and I don't want to duplicate all the swfs in each project... So I need another solution.

                  • 6. Re: Embed Font and change textField font in different swf
                    Flex harUI Adobe Employee

                    AIR apps place all SWFs from outside the application-directory in security

                    sandboxes.

                     

                    You can try loading the SWF as a bytearray and using loadBytes

                    • 7. Re: Embed Font and change textField font in different swf
                      eprevot123 Level 2

                      I tried the same code in a Flex application and the result is the same so it's not specific to Air app...

                       

                      I tried to load the swf in the same security sandbox using :

                      new LoaderContext(false, null, SecurityDomain.currentDomain);

                      but it ends in a runtime SecurityError: Error #2142

                       

                      I don't know how to load the swf in the same sandox then.

                       

                      I'll try the loadBytes method.