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. 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.
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:
var fontLoader:FontLoader = new FontLoader("http://path/to/swf/_Bradley.swf");
Of course, I’ve replaced the real path for this example.