実行時に共有される TLFTextfields とフォントを使用しているときに (flash cs5 で) 問題を発見しました。
これがシナリオです。
- Fonts.swf: フォントのライブラリ (ランタイム共有 DF4)
- Popup.swf: Fonts.swf のフォントを使用して TLFTextfield (テキストを含む) を含むポップアップ
- Main.swf : Popup.swf をロードおよびアンロードするボタンを備えたメインの swf (Loader または SafeLoaderを使用しても同じ結果が得られます)
シンプルで素敵な、
main.swf を実行し、ボタンをクリックすると、テキストとともにポップアップが表示されます。ボタンをもう一度クリックすると、ポップアップが削除されます。さて、ボタンをもう一度クリックすると、次のエラーが表示されます。
ArgumentError: Error #1508: The value specified for argument font is invalid.
at flash.text::Font$/registerFont()
at Popup_fla::MainTimeline()[Popup_fla.MainTimeline::MainTimeline:12]
フォントが既に登録されているために発生していると推測しています(ロード前にクリックするとチェックされます)。
これを乗り越える方法を知っている人はいますか?
あなたが疑問に思っているなら、ここに私の Main.as があります
package
{
import fl.controls.Button;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.MouseEvent;
import flash.events.UncaughtErrorEvent;
import flash.net.URLRequest;
import flash.text.Font;
public class Main extends Sprite
{
public var testPopupBtn:Button;
protected var loader:Loader;
public function Main()
{
trace("Main.Main()");
testPopupBtn.label = "open";
testPopupBtn.addEventListener(MouseEvent.CLICK, testClickHandler);
}
protected function testClickHandler(event:MouseEvent):void
{
trace("Main.testClickHandler(event)");
if(loader)
{
testPopupBtn.label = "open";
this.removeChild(loader);
//loader.unloadAndStop();
loader = null;
}else{
testPopupBtn.label = "close";
trace("Registered Fonts -->");
var fonts:Array = Font.enumerateFonts(false);
for each (var font:Font in fonts) {
trace("\t",font.fontName, font.fontStyle, font.fontType);
}
trace("<--");
loader = new Loader();
loader.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler);
this.addChild(loader);
try{
loader.load(new URLRequest("Popup.swf"));
}catch(e:*){
trace(e);
}
}
}
private function uncaughtErrorHandler(event:UncaughtErrorEvent):void
{
trace("Main.uncaughtErrorHandler(event)", event);
}
}
}