# Loading Fonts at Runtime

**URL:** <https://forum.kirupa.com/t/loading-fonts-at-runtime/293573>\
**Category:** flash\
**Created:** [July 30, 2009, 10:13pm UTC](https://forum.kirupa.com/t/loading-fonts-at-runtime/293573 "2009-07-30T22:13:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anakadote](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/anakadote/32/2119_2.png) [@anakadote](https://forum.kirupa.com/u/anakadote)\
**Post date:** [July 30, 2009, 10:13pm UTC](https://forum.kirupa.com/t/loading-fonts-at-runtime/293573/1 "2009-07-30T22:13:27Z")

</div>

Posting this is my last resort—I’ve spent the entire afternoon trying to figure this out. I’m to load a font at runtime using some updated code found [here](http://www.betriebsraum.de/blog/2007/06/22/runtime-font-loading-with-as3-flash-cs3-not-flex/). The problem is no matter what I try I always get the following error:

TypeError: Error #2007: Parameter font must be non-null.  
at flash.text::Font$/registerFont()  
at cardmaker::FontLoader/fontLoaded()

which is saying that “FontLibrary.\_Bradley” is null in registerFont(); I know the swf exists on the server and the font symbol is being Exported for ActionScript with a class name and symbol name of both “\_Bradley”. Any help would be incredibly appreciated.

```auto
package cardmaker {
 
     import flash.display.Loader;
     import flash.display.Sprite;
     import flash.events.Event;
     import flash.net.URLRequest;
     import flash.text.*;

     public class FontLoader extends Sprite {

          public function FontLoader(font:String) {
               loadFont(font);
          }

          private function loadFont(url:String):void {
               var loader:Loader = new Loader();
               loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fontLoaded);
               loader.load(new URLRequest(url));
          }

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

          public function drawText():void {
               var tf:TextField = new TextField();
               tf.defaultTextFormat = new TextFormat("Bradley Hand ITC TT-Bold", 16, 0);
               tf.embedFonts = true;
               tf.antiAliasType = AntiAliasType.ADVANCED;
               tf.autoSize = TextFieldAutoSize.LEFT;
               tf.border = true;
               tf.text = "Scott was here
Scott was here too
blah scott...:;*&^% ";
               tf.rotation = 15;

               addChild(tf);
          }
     }
}

```

Usage:

```auto
var fontLoader:FontLoader = new FontLoader("http://path/to/swf/_Bradley.swf");

```

Of course, I’ve replaced the real path for this example.
