無理やりフォントローディング
...
@author DefaultUser (Tools -> Custom Arguments...)
package
{
import flash.net.URLLoader;
import flash.system.Security;
import flash.system.ApplicationDomain;
import flash.net.URLRequest;
import flash.net.URLLoaderDataFormat;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.IOErrorEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.system.LoaderContext;
import flash.text.Font;
import flash.utils.getQualifiedClassName;
/**
* ...
* @author DefaultUser (Tools -> Custom Arguments...)
*/
public class FontLoading2 extends Sprite
{
private var _urlLoader:URLLoader;
private var _loader_url:String = "http://www.matzmtok.com/wonderfl/font_loader.swf";
private var _textField:TextField;
public function FontLoading2()
{
Security.loadPolicyFile('http://www.matzmtok.com/wonderful/crossdomain.xml');
_urlLoader = new URLLoader();
_urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
_urlLoader.addEventListener(Event.COMPLETE, completeHandler);
_urlLoader.addEventListener(Event.OPEN, openHandler);
_urlLoader.addEventListener(ProgressEvent.PROGRESS, progressHandler);
_urlLoader.load(new URLRequest(_loader_url));
_textField = new TextField();
_textField.x = 10;
_textField.y = 10;
_textField.width = stage.stageWidth - 20;
_textField.height = stage.stageHeight - 20;
_textField.multiline = true;
_textField.text = "Font Loading Demo\n";
addChild(_textField);
}
private function openHandler(e:Event):void
{
_textField.appendText("Start Loading\n");
}
private function progressHandler(e:ProgressEvent):void
{
var percent:Number = Math.round( 100 * e.bytesLoaded / e.bytesTotal);
_textField.appendText("Loading... " + percent + "%\n");
}
private function completeHandler(e:Event):void
{
_textField.appendText("Complete Loader Loading\n");
var l:URLLoader = e.target as URLLoader;
var swfLoader:Loader = new Loader();
swfLoader.loadBytes(l.data);
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaderComplete);
}
private function swfLoaderComplete(e:Event):void
{
var info:LoaderInfo = e.target as LoaderInfo;
var clsFontLoader:Class = info.applicationDomain.getDefinition('ru.etcs.utils.FontLoader') as Class;
if (clsFontLoader) {
var fl:* = new clsFontLoader();
fl.load(new URLRequest("http://www.matzmtok.com/wonderfl/fonts.swf"));
fl.addEventListener(Event.COMPLETE, loaderCompleteHandler);
}
}
private function loaderCompleteHandler(e:Event):void
{
_textField.appendText("Font Loading Complete\n");
showFontList();
}
private function showFontList():void {
Font.enumerateFonts().forEach(dump);
}
private function dump(element:*, index:int, src:Array):void {
var font:Font = element as Font;
_textField.appendText("fontName:" + font.fontName +
" fontStyle:" + font.fontStyle + " fontType:" + font.fontType +"\n");
var tf:TextField = new TextField();
var format:TextFormat = new TextFormat(font.fontName, 30, 0x00ccff);
var msg:String = "0123456789abcdefghijklmnopqrstuvwxyz";
tf.embedFonts = true;
tf.defaultTextFormat = format;
tf.text = msg;
tf.x = 10;
tf.y = 30 * index + 150;
tf.autoSize = TextFieldAutoSize.LEFT;
addChild(tf);
}
}
}