Here is the code which I have to perform this task . Commonly, I issued a button, a file open dialog pops up, and then I use a Loader to load the SWF. But I don't have any idea about the registration procedure of the font after that? Is what I am manipulating in fontLoaded() fine ?
Code:
import flash.utils.describeType;
import mx.controls.SWFLoader;
private var FtFile: FileReference = new FileReference();
private var Ft: File = new File();
private function initApp(): void
{
var embdFonts: Array = Font.enumerateFonts(false);
trace ("=== BEFORE ===");
for (var lpi: int = 0; lp < embdFonts.length; lp++)
{
var item: Font = embdFonts[lp];
trace("["+lp+"] name: "+item.fontName + ", style: "+ item.fontStyle+", type: "+item.fontType);
}
btnLoadFont.addEventListener(MouseEvent.CLICK, loadFont);
}
private function loadFont(e: MouseEvent): void
{
Ft.browseForOpen("Select Font");
Ft.addEventListener(Event.SELECT, fontSelect);
}
private function fontSelect(e: Event): void
{
trace("File: "+Ft.url);
var loader: Loader = new Loader();
var context: LoaderContext;
var loaderInfo: LoaderInfo = loader.contentLoaderInfo;
loaderInfo.addEventListener(Event.COMPLETE, fontLoaded);
context = new LoaderContext( true, new ApplicationDomain( ApplicationDomain.currentDomain ) );
loader.load(new URLRequest(Ft.url), context);
}
private function fontLoaded(e: Event): void
{
trace(e.target);
var FtLib:Class = ApplicationDomain((e.target as LoaderInfo).applicationDomain).getDefinition('_Verdana') as Class;
Font.registerFont(FtLib);
var embdFonts: Array = Font.enumerateFonts(false);
trace("=== AFTER ===");
for (var lp: int = 0; lp < embdFonts.length; lp++)
{
var item: Font = embdFonts[lp];
trace("["+lp+"] name: "+item.fontName + ", style: "+ item.fontStyle+", type: "+item.fontType);
}
}
Bookmarks