title: Example of using embedded fonts loaded at runtime Flex 4 runtime loaded modules
body: <p>am having quite alot of problems trying to use embeded fonts in flex 4. Here is the situation.</p>
  
  <p>I have a main application that fist load the fonts via a URL. This is the font file code:</p>
  
  <pre><code>package{
  import flash.display.Sprite;
  import flash.text.Font;
  
  public class FontLib extends Sprite
  {
  
      [Embed(source="MyriadPro-Regular.otf", fontWeight= "normal", fontName="Myriad Pro", fontFamily="Myriad Pro",mimeType="application/x-font", embedAsCFF="true")]
      public const myriadFont:Class;
  
      public function FontLib()
      {
          Font.registerFont(myriadFont);
          var fonts:Array = Font.enumerateFonts(false);
          trace('libsss',fonts); 
      }
  }}
  </code></pre>
  
  <p>That seems to work ok. As the trace shows the embedded font when the font swf is loaded.</p>
  
  <pre><code>[SWF] /assets/FontLib.swf - 89,594 bytes after decompression libsss [object Font],[object FontLib_myriadFont]
  </code></pre>
  
  <p>Once the font swf is loaded I then load the fist module via a URL using ModuleLoader. In the module I execute the following code on creation complete to see if the fonts are loaded:</p>
  
  <pre><code>protected function bookstoremodule1_creationCompleteHandler(event:FlexEvent):void
          {
  
              var fonts:Array = Font.enumerateFonts(false);
              trace('bs',fonts); // This shows Verdana as a registered font
          }
  </code></pre>
  
  <p>Thats loaded module seem to have picked up the font:</p>
  
  <pre><code>load module success: bs [object FontLib_myriadFont]
  </code></pre>
  
  <p>However when I cannot get it to apply to a spark RichText component. Here is the mxml for it:</p>
  
  <pre><code>&lt;s:RichText fontLookup="embeddedCFF" renderingMode="cff" ai:aa="2" color="#2F4160" columnCount="1" fontFamily="Myriad Pro" fontSize="18.0737" height="20" d:id="4" kerning="on" tabStops="S40.665699005127 S81.3313980102539 S121.997097015381 S162.662796020508" text="Shopping Cart (0)" d:userLabel="Shopping Cart (0)" flm:variant="1" whiteSpaceCollapse="preserve" width="168" x="53" y="12" x.down="54" y.down="13" id="richtext1"&gt;
      &lt;s:filters&gt;
          &lt;s:DropShadowFilter blurX="0" blurY="0" color="#FFFFFF" distance="1.41421" quality="2"/&gt;
      &lt;/s:filters&gt;
  &lt;/s:RichText&gt;
  </code></pre>
  
  <p>The mxml definition is fine when the font is embedded directly in the module. It just stops working when the font is loaded as a swf. </p>
  
  <p>Any ideas? I have tried loads of things but still having no luck :(</p>
  
  <p>Thanks </p>